Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby Scripts To Make Life Easier

Ruby Scripts To Make Life Easier

Introduction to subprocesses and how to use them for everyday use.

Paulo Ancheta

December 06, 2016
Tweet

More Decks by Paulo Ancheta

Other Decks in Programming

Transcript

  1. # talk* #! bin/env ruby `echo hello world` $ mv

    talk.rb talk $ chmod u+x talk $ ./talk hello world
  2. # talk* #! bin/env ruby string = “hello world” `echo

    #{string.gsub(/world/, “VanRuby”) } | grep file.txt` $ ./talk | more file.txt hello VanRuby
  3. # clean-pg* #! bin/env ruby pg = `ps aux |

    grep postgres | grep waiting` pg = pg.split(/\n/) pg.each do |waiting| # ... some process to get the pid `kill #{pid}` end
  4. # split-branch* #! bin/env ruby # commits => 1z2y3 TICKET-number

    msg specific_commits = `git log - -pretty - -oneline | grep #{ARGV}` `git checkout master && git pull origin master && git checkout -b test-branch` specific_commits.each do |commit| sha = commit[0..6] # => [123asdf, qwer456, … ] `git cherry-pick #{sha}` end