Slide 1

Slide 1 text

Ruby Scripts to Make Life Easier #MakeRubyGreatAgain

Slide 2

Slide 2 text

@PauloAncheta

Slide 3

Slide 3 text

We make alias-es all the time. We should make something more useful.

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

# talk* #! bin/env ruby `echo hello world` $ mv talk.rb talk $ chmod u+x talk $ ./talk hello world

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

$ 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

Slide 9

Slide 9 text

irb(main):003:0> system `ls` => true

Slide 10

Slide 10 text

All of that is great. How can I be productive doe?

Slide 11

Slide 11 text

# 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

Slide 12

Slide 12 text

# 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

Slide 13

Slide 13 text

#MakeRubyGreatAgain