z, ? | toggle help (this) |
space, → | next slide |
shift-space, ← | previous slide |
d | toggle debug mode |
## <ret> | go to slide # |
c, t | table of contents (vi) |
f | toggle footer |
r | reload slides |
n | toggle notes |
p | run preshow |
$ fantastic --help
Usage: fantastic [options] conference
Options:
--location, -l <s>: Conference location
--help, -h: Show this message
$ fantastic --location Müggelsee eurucamp
eurucamp at Müggelsee is fantastic! \o/
bin/fantastic
#!/usr/bin/env ruby
bin/fantastic
#!/usr/bin/env ruby
require_relative '../lib/fantastic/executable'
bin/fantastic
#!/usr/bin/env ruby
require_relative '../lib/fantastic/executable'
Fantastic::Executable.new(ARGV).run
lib/fantastic/executable.rb
module Fantastic class Executable
def run
puts "#{@conf} at #{@opts[:location]} is fantastic! \\o/"
end
end end
lib/fantastic/executable.rb
module Fantastic class Executable
def initialize args
end
def run
puts "#{@conf} at #{@opts[:location]} is fantastic! \\o/"
end
end end
lib/fantastic/executable.rb
require 'trollop'
module Fantastic class Executable
def initialize args
@opts = Trollop.options args do
opt :location, 'Conference location', type: String
end
end
def run
puts "#{@conf} at #{@opts[:location]} is fantastic! \\o/"
end
end end
lib/fantastic/executable.rb
require 'trollop'
module Fantastic class Executable
def initialize args
@opts = Trollop.options args do
banner 'Usage: fantastic [options] conference'
banner 'Options:'
opt :location, 'Conference location', type: String
end
end
def run
puts "#{@conf} at #{@opts[:location]} is fantastic! \\o/"
end
end end
lib/fantastic/executable.rb
require 'trollop'
module Fantastic class Executable
def initialize args
@opts = Trollop.options args do
banner 'Usage: fantastic [options] conference'
banner 'Options:'
opt :location, 'Conference location', type: String
end
@conf = args.first
end
def run
puts "#{@conf} at #{@opts[:location]} is fantastic! \\o/"
end
end end
spec/fantastic/executable_spec.rb
require 'minitest/autorun'
require_relative '../../lib/fantastic/executable'
module Fantastic describe Executable do
end end
spec/fantastic/executable_spec.rb
require 'minitest/autorun'
require_relative '../../lib/fantastic/executable'
module Fantastic describe Executable do
describe '#run' do
it 'works as expected' do
end
end
end end
spec/fantastic/executable_spec.rb
# encoding: UTF-8
require 'minitest/autorun'
require_relative '../../lib/fantastic/executable'
module Fantastic describe Executable do
describe '#run' do
it 'works as expected' do
Executable.new(['--location', 'Müggelsee', 'eurucamp']).run
out.must_include 'eurucamp at Müggelsee is fantastic! \o/'
end
end
end end
spec/fantastic/executable_spec.rb
# encoding: UTF-8
require 'minitest/autorun'
require_relative '../../lib/fantastic/executable'
module Fantastic describe Executable do
describe '#run' do
it 'works as expected' do
out = capture_io do
Executable.new(['--location', 'Müggelsee', 'eurucamp']).run
end
out.must_include 'eurucamp at Müggelsee is fantastic! \o/'
end
end
end end
spec/fantastic/executable_spec.rb
# encoding: UTF-8
require 'minitest/autorun'
require_relative '../../lib/fantastic/executable'
module Fantastic describe Executable do
describe '#run' do
it 'works as expected' do
out, err = capture_io do
Executable.new(['--location', 'Müggelsee', 'eurucamp']).run
end
out.must_include 'eurucamp at Müggelsee is fantastic! \o/'
err.must_be :empty?
end
end
end end
--long
-s
--no-*
switchesgem-man
+ ronn
ARGV
& ARGF
$ cat confs.2012.1
wroc_love.rb
SRC
$ cat confs.2012.2
eurucamp
Arrrrcamp
RuPy
$ ruby -e 'p ARGV' confs.2012.*
["confs.2012.1", "confs.2012.2"]
$ ruby -e 'p ARGF.to_a' confs.2012.*
["wroc_love.rb\n", "SRC\n", "eurucamp\n", "Arrrrcamp\n", "RuPy\n"]
$ ruby -e 'p ARGF.path; ARGF.skip; p ARGF.to_a' confs.2012.*
"confs.2012.1"
["eurucamp\n", "Arrrrcamp\n", "RuPy\n"]
$stdout
$stderr
$stdin
$stdout
$stderr
$stdin
STDOUT
STDERR
STDIN
FileUtils
& tempfile
FileUtils.mkdir_p '/tmp/foo/bar/baz'
FileUtils.rm_rf '/tmp/foo'
let(:file) { Tempfile.new 'foo' }
# #<File:/tmp/foo20120818-21526-12fjarq>
# no need to remove afterwards
let(:path) { Dir.mktmpdir }
# "/tmp/d20120818-21526-11xj17r"
after { FileUtils.rmtree path }
~/.config/fantastic
~/.cache/fantastic
~/.local/shared/fantastic
gem install xdg
XDG['CONFIG'] # '/home/chastell/.config'
XDG['CACHE'] # '/home/chastell/.cache'
XDG['DATA'] # '/home/chastell/.local/share'
path = '/etc/passwd'
out = system "cat #{path}" # UNSAFE
path = '/etc/passwd; rm -rf /etc'
out = system "cat #{path}" # UNSAFE
path = '/etc/passwd; rm -rf /etc'
out = system 'cat', path
path = '/etc/passwd; rm -rf /etc'
out = system *%W[cat #{path}]
$PROGRAM_NAME = 'fantastic'
$PROGRAM_NAME = "dump (#{progress}% complete)"
$PROGRAM_NAME = "dump (#{time}s left)"
exit
exit 1
Errs = { foo: 1, bar: 2, baz: 4, qux: 64 }
exit Errs[:foo] | Errs[:baz] | Errs[:qux]
abort 'bad user!'
Signal.list
trap :EXIT { puts 'so exiting!' }
:TERM
vs :KILL
:INT # ctrl-c
:HUP # config
:USR1 # debug?
QUIT | wait for child to finish then exit |
---|---|
TERM, INT | immediately kill child then exit |
USR1 | immediately kill child but don’t exit |
USR2 | don’t start to process any new jobs |
CONT | process new jobs again after a USR2 |
HUP | reloads config and restart workers |
---|---|
INT, TERM | quick shutdown, kills all workers |
QUIT | graceful shutdown master |
USR1 | reopen all logs |
USR2 | reexecute the running binary |
WINCH | gracefully stops workers |
TTIN | increment number of workers by one |
TTOU | decrement number of workers by one |
trap :PIPE, :EXIT
$ ruby -e '$stdout.sync = true; loop { puts "."; sleep 1 }' | head -3
.
.
.
-e:1:in `write': Broken pipe - <STDOUT> (Errno::EPIPE)
from -e:1:in `puts'
from -e:1:in `puts'
from -e:1:in `block in <main>'
from -e:1:in `loop'
from -e:1:in `<main>'
$ ruby -e '…; trap(:PIPE, :EXIT); loop { puts "."; sleep 1 }' | head -3
.
.
.
$ # next command
rows, cols = `stty size`.split.map &:to_i
progressbar
& progress
terminal-tables
& hirb
rainbow
& painter
$stdout.tty?