$30 off During Our Annual Pro Sale. View details »

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. Ruby Scripts to Make Life Easier #MakeRubyGreatAgain

  2. @PauloAncheta

  3. We make alias-es all the time. We should make something

    more useful.
  4. # talk.rb system “echo hello world” $ ruby talk.rb hello

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

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

    #{string}` $ ./talk hello world
  7. # talk* #! bin/env ruby string = “hello world” `echo

    #{string.gsub(/world/, “VanRuby”) } | grep file.txt` $ ./talk | more file.txt hello VanRuby
  8. $ irb irb(main):001:0> files = `ls` => “Applications\nDesktop\nDocuments\nDow nloads\nLibrary\nMovies\nMusic\nPictur es\nPublic\ntalk\n”

    irb(main):002:0> files.class => String
  9. irb(main):003:0> system `ls` => true

  10. All of that is great. How can I be productive

    doe?
  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
  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
  13. #MakeRubyGreatAgain