Slide 1

Slide 1 text

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

Slide 41

Slide 41 text

--XTerm--------------------------- | | | --outer bash---------------- | | | | | | | --script-------------- | | | | | | | | | | | --inner bash---- | | | | | | | | | | | | | | | $ | | | | | | | ---------------- | | | | | | | | | | | ---------------------- | | | | | | | ---------------------------- | | | ----------------------------------

Slide 42

Slide 42 text

Requirements for the recorder

Slide 43

Slide 43 text

works on both Linux and OSX has minimum dependencies has simplest possible installation is targetted not only at Rubyists

Slide 44

Slide 44 text

script.rb?

Slide 45

Slide 45 text

script.rb pros Ruby! Ruby has PTY module in stdlib

Slide 46

Slide 46 text

script.rb cons WELL... RUBY

Slide 47

Slide 47 text

Requires ruby installed

Slide 48

Slide 48 text

PTY module differs between 1.8 / 1.9

Slide 49

Slide 49 text

I don't control user environment DOES USER HAVE 1.8 OR 1.9? NO RUBY AT ALL?

Slide 50

Slide 50 text

script.py?

Slide 51

Slide 51 text

script.py pros Python is preinstalled on Linux/OSX Python has pty module in stdlib

Slide 52

Slide 52 text

pty module haven't changed in years

Slide 53

Slide 53 text

LIKE IN 10+ YEARS

Slide 54

Slide 54 text

script.py then! ~400 LOC no dependencies records STDOUT + timing info saves env info ($TERM, $SHELL...) uploads

Slide 55

Slide 55 text

"It was just safer to use Python here" - Me.

Slide 56

Slide 56 text

Term recording ✔

Slide 57

Slide 57 text

The site

Slide 58

Slide 58 text

Requirements for the site Replaying asciicast Browsing through asciicasts Basic (optional) profile

Slide 59

Slide 59 text

Next slide will be boring...

Slide 60

Slide 60 text

Site is built in Rails * here you can use Ruby

Slide 61

Slide 61 text

The player

Slide 62

Slide 62 text

Ruby?

Slide 63

Slide 63 text

Ruby in the browser NaCl in Chrome JRuby in Applet other hacks..?

Slide 64

Slide 64 text

Java applet?

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Flash?

Slide 67

Slide 67 text

"That Steve guy famously said it's proprietary and closed, too." http://isflashdeadyet.com/

Slide 68

Slide 68 text

Javascript?

Slide 69

Slide 69 text

Javascript then! TECHNICALLY COFFEESCRIPT :)

Slide 70

Slide 70 text

HTML5 based VT100/102 implementation

Slide 71

Slide 71 text

Multiple renderers:
 and 
Fast
Tested with Jasmine


Slide 72

Slide 72 text

Renderers 2 AVAILABLE NOW:
 , with "copy & paste"
 , faster, no "copy & paste"
TODO: WebGL based one


Slide 73

Slide 73 text

Fast & responsive THANKS TO HTML5 requestAnimationFrame WebWorker

Slide 74

Slide 74 text

Soon to be extracted from ascii.io

Slide 75

Slide 75 text

Replaying ✔

Slide 76

Slide 76 text

Thumbnails

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

Requirements for thumbnail generation

Slide 79

Slide 79 text

thumbnail is just a text generation happens in background after uploading takes terminal snapshot at 10 sec mark

Slide 80

Slide 80 text

ffmpeg? WELL, NO. IT'S NOT VIDEO FILE.

Slide 81

Slide 81 text

Xvfb + xterm + scriptreplay? WELL, NO. SCRIPTREPLAY DOESN'T DO SNAPSHOTS.

Slide 82

Slide 82 text

Xvfb + xterm + scriptreplay + screenshot? WELL, NO. I WANT TEXT.

Slide 83

Slide 83 text

scriptreplay won't do then...

Slide 84

Slide 84 text

nodejs maybe?

Slide 85

Slide 85 text

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

Slide 96

Slide 96 text

Great! Works! BUT LET'S LOOK AT IT AGAIN...

Slide 97

Slide 97 text

Use shell script instead!

Slide 98

Slide 98 text

// script/capture.sh #!/bin/bash ... tmux new -s $SESS_ID -d -x $COLS -y $LINES "scriptreplay ...." sleep 10 tmux capture-pane -t $SESS_ID tmux save-buffer - tmux kill-session -t $SESS_ID &>/dev/null

Slide 99

Slide 99 text

// app/jobs/capture_job.rb class CaptureJob def self.perform(...) ... text = `SESS_ID=#{sess_id} COLS=#{cols} ... script/capture.sh` ... end end

Slide 100

Slide 100 text

Thumbnails ✔

Slide 101

Slide 101 text

Example use cases

Slide 102

Slide 102 text

Tutorials Rails blog app in 15 minutes? ;) Vim git shell tricks

Slide 103

Slide 103 text

Bug reporting app starts leaking memory app starts eating CPU

Slide 104

Slide 104 text

Auto-recording of shell sessions

Slide 105

Slide 105 text

# end of .bashrc if [ -z "$RECORDING" ]; then export RECORDING=1 ASCII_IO_API_URL=http://localhost:3000 exec asciiio -y fi Thx @roy & @_solnic_ !

Slide 106

Slide 106 text

It's open-source Web app: github.com/sickill/ascii.io Recorder: github.com/sickill/ascii.io-cli CONTRIBUTE!

Slide 107

Slide 107 text

Summary

Slide 108

Slide 108 text

Use Ruby where it makes sense

Slide 109

Slide 109 text

Use Python where it makes sense

Slide 110

Slide 110 text

Use X where it makes sense

Slide 111

Slide 111 text

Thanks! QUESTIONS PLEASE! Twitter/Github: @sickill