Ruby Scripts To Make Life Easier

Ruby Scripts To Make Life Easier

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

7ae2c5cad3f71b75706b118c3d06c7b2?s=128

Paulo Ancheta

December 06, 2016
Tweet

Transcript

  1. 5.

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

    talk.rb talk $ chmod u+x talk $ ./talk hello world
  2. 7.

    # talk* #! bin/env ruby string = “hello world” `echo

    #{string.gsub(/world/, “VanRuby”) } | grep file.txt` $ ./talk | more file.txt hello VanRuby
  3. 11.

    # 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. 12.

    # 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