Don't use Ruby*
* unless otherwise stated
ASCII.IO CASE STUDY
NERD CONTENT
WARNING!
Slide 2
Slide 2 text
MARCIN KULIK
Slide 3
Slide 3 text
I WORK AT
Slide 4
Slide 4 text
I CURRENTLY WORK ON:
kanbanery.com
Slide 5
Slide 5 text
I SHARE AT GITHUB & TWITTER AS SICKILL
Slide 6
Slide 6 text
YOU MAY KNOW ME FROM:
racksh, ascii.io, git-dude, vim-pasta, bitpocket, coloration,
stderred...
All of them available at https://github.com/sickill/
Slide 7
Slide 7 text
Don't use Ruby
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
Use the right tool
for the right job
Slide 10
Slide 10 text
Quick
history
lesson
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
VT100
RELEASED IN 1978
FOUNDATION FOR TERMINALS WE USE
Slide 14
Slide 14 text
Developer's
workflow
Slide 15
Slide 15 text
rake
git
vim
rails {generate, console, ...}
Slide 16
Slide 16 text
Screencasts
Slide 17
Slide 17 text
"Recording the work in your terminal with screen
capture software and serving it as a video is like
recording your text reply as an .mp3 file and
sending it via email" - Me.
Slide 18
Slide 18 text
typescript
Slide 19
Slide 19 text
/usr/bin/script
Slide 20
Slide 20 text
# man script
NAME
script — make typescript of terminal session
DESCRIPTION
script makes a typescript of everything printed on your
terminal. It is useful for students who need a hardcopy
record of an interactive session as proof of an assignment,
as the typescript file can be printed out later with lpr(1).
Slide 21
Slide 21 text
RECORDING:
$ script -t session1 2>session1.time
Slide 22
Slide 22 text
/usr/bin/scriptreplay
Slide 23
Slide 23 text
# man scriptreplay
NAME
scriptreplay - play back typescripts,
using timing information
DESCRIPTION
This program replays a typescript, using timing
information to ensure that output happens at the
same speed as it originally appeared when the
script was recorded.
Slide 24
Slide 24 text
REPLAYING:
$ scriptreplay foo.time foo
Slide 25
Slide 25 text
Sharing
Slide 26
Slide 26 text
Requirements for
sharing
Simplest possible recording in the
terminal
Simplest possible replay in the browser
Slide 27
Slide 27 text
ascii.io was born
Slide 28
Slide 28 text
"ASCII.IO is the simplest way to record your
terminal and share the recordings with your
fellow geeks. Simply record and upload your
terminal session with single command, and
ASCII.IO will play it back in your browser."
Slide 29
Slide 29 text
Quick demo
APP SCROLS BY DR NIC
Slide 30
Slide 30 text
4 building blocks
of ascii.io
Slide 31
Slide 31 text
terminal recorder
http://ascii.io/ site with an API
in-browser player
background job for thumbnails
Slide 32
Slide 32 text
terminal recorder
http://ascii.io/ site with an API
in-browser player
background job for thumbnails
Slide 33
Slide 33 text
The recorder
Slide 34
Slide 34 text
Recording is
covered
/USR/BIN/SCRIPT
Slide 35
Slide 35 text
Well, on Linux yes
Slide 36
Slide 36 text
On OSX
/usr/bin/script is
crippled
Slide 37
Slide 37 text
A little bit of Yak
Shaving
Slide 38
Slide 38 text
script.c
433 LINES OF C CODE
CREATES PTY - PSEUDO-TERMINAL
Slide 39
Slide 39 text
How script.c
works
Slide 40
Slide 40 text
it has its STDIN and STDOUT connected
to the terminal app
it forks and execs shell in child process
it gets file descriptors for spawned
process' STDIN and STDOUT
it proxies STDIN and STDOUT and saves
STDOUT to a file
Maybe, via:
standalone nodejs bin
therubyracer gem
Slide 86
Slide 86 text
Something told
me to man tmux
Slide 87
Slide 87 text
tmux?
Slide 88
Slide 88 text
"tmux is a terminal multiplexer: it enables a
number of terminals to be created, accessed,
and controlled from a single screen. tmux may
be detached from a screen and continue running
in the background, then later reattached."
Slide 89
Slide 89 text
How tmux fits
here???
Slide 90
Slide 90 text
$ man tmux
capture-pane [-b buffer-index] [-E end-line]
[-S start-line] [-t target-pane]
Capture the contents of a pane to the specified
buffer, or a new buffer if none is specified.
Slide 91
Slide 91 text
$ man tmux
save-buffer [-a] [-b buffer-index] path
Save the contents of the specified paste buffer
to path. The -a option appends to rather than
overwriting the file.
Slide 92
Slide 92 text
scriptreplay will
do then!
Slide 93
Slide 93 text
Plan
Slide 94
Slide 94 text
BACKGROUND JOB THAT:
creates new, detached tmux session
runs `scriptreplay` in it
waits for 10 sec
runs `tmux capture-pane`
runs `tmux save-buffer`
Slide 95
Slide 95 text
// app/jobs/capture_job.rb
class CaptureJob
def self.perform(...)
...
system "tmux new -s $SESS_ID -d -x $X -y $Y 'scriptreplay ....'"
sleep 10
system "tmux capture-pane -t $SESS_ID"
text = `tmux save-buffer -`
system "tmux kill-session -t $SESS_ID &>/dev/null"
...
end
end