Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Ruby Scripts To Make Life Easier
Paulo Ancheta
December 06, 2016
Programming
1
110
Ruby Scripts To Make Life Easier
Introduction to subprocesses and how to use them for everyday use.
Paulo Ancheta
December 06, 2016
Tweet
Share
More Decks by Paulo Ancheta
See All by Paulo Ancheta
pauloancheta
0
30
pauloancheta
0
33
Other Decks in Programming
See All in Programming
legalforce
PRO
0
610
tetsukick
0
180
mihyaeru21
0
360
lilobase
PRO
1
710
line_developers_tw2
0
360
hassaku63
1
700
yasaichi
30
7.7k
vixentael
0
310
danilop
1
730
christianweyer
PRO
0
270
neripark
3
570
kgmyshin
1
440
Featured
See All Featured
carmenhchung
31
1.5k
geeforr
332
29k
sugarenia
233
850k
jnunemaker
PRO
40
4.6k
michaelherold
224
8.5k
jeffersonlam
329
15k
rocio
155
11k
roundedbygravity
242
21k
malarkey
192
8.6k
shpigford
165
19k
schacon
145
6.6k
brettharned
93
3k
Transcript
Ruby Scripts to Make Life Easier #MakeRubyGreatAgain
@PauloAncheta
We make alias-es all the time. We should make something
more useful.
# talk.rb system “echo hello world” $ ruby talk.rb hello
world
# talk* #! bin/env ruby `echo hello world` $ mv
talk.rb talk $ chmod u+x talk $ ./talk hello world
# talk* #! bin/env ruby string = “hello world” `echo
#{string}` $ ./talk hello world
# talk* #! bin/env ruby string = “hello world” `echo
#{string.gsub(/world/, “VanRuby”) } | grep file.txt` $ ./talk | more file.txt hello VanRuby
$ 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
irb(main):003:0> system `ls` => true
All of that is great. How can I be productive
doe?
# 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
# 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
#MakeRubyGreatAgain