Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line

Arc & Codementor
Arc & CodementorArc & Codementor
stdin, 
stdout 
pup, Go & life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
stdin, 
stdout 
pup, Go & life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
$ cd ~/talks/codementor 
$ cat hello.txt 
Hello, Code Mentor! 
$
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
CLI life: Data
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
data
[LOG] some data 
[LOG] more data 
[LOG] even more
col1,col2,col3 
some,data,and 
even,more,data
{ 
“some”: “data”, 
“more”: “data” 
}
<div> 
<h1>Some</h1> 
<p>data</p> 
</div>
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
grep & nl
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
cat grep
cat grep
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
pipes!
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
curl & wget
$ wget -O Shakespeare.txt  
http://gutenberg.org/cache/epub/100/pg100.txt
$ wget -O Shakespeare.txt  
http://gutenberg.org/cache/epub/100/pg100.txt
$ wget -O Shakespeare.txt  
http://gutenberg.org/cache/epub/100/pg100.txt
wget =
$ wget --load-cookies cookies.txt
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
$ wget -O Shakespeare.txt  
http://gutenberg.org/cache/epub/100/pg100.txt
$ curl -o Shakespeare.txt  
http://gutenberg.org/cache/epub/100/pg100.txt
$ cat Shakespeare.txt |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
$ curl http://gutenberg.org... |  
sed -e 's/s+/n/g' |  
tr -d ' ' |  
grep -e '^$' -v |  
tr '[:upper:]' '[:lower:]' |  
sort | uniq -c | sort -nr |  
head -n 50
curl & 
wget
curl & 
wget
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
I hate HTML
HTML is 
really hard
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
“Every time you attempt to 
parse HTML with regular 
expressions, the unholy child 
weeps the blood of virgins, 
and Russian hackers pwn 
your webapp.”
“Have you tried using an 
XML parser instead?”
But it gets 
worse
<tbody> 
<tr><img src="foo"></tr> 
<tr><img/><br> 
</tbody> 
</table>
Yes, this is valid HTML: 
<tbody> 
<tr><img src="foo"></tr> 
<tr><img/><br> 
</tbody> 
</table>
Yes, this is valid HTML: 
<tbody> 
<tr><img src="foo"></tr> 
<tr><img/><br> 
</tbody> 
</table>
Yes, this is valid HTML: 
<tbody> 
<tr><img src="foo"></tr> 
<tr><img/><br> 
</tbody> 
</table>
Yes, this is valid HTML: 
<tbody> 
<tr><img src="foo"></tr> 
<tr><img/><br> 
</tbody> 
</table>
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
NEVER TRY 
TO WRITE AN 
HTML PARSER
Nokogiri 鋸
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
pup
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Still HTML
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
$ curl -L -s reddit.com/r/programming/ |  
pup p.title a[href^=http] attr{href} 
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] attr{href}
$ curl -L -s reddit.com/r/programming/ |  
pup p.title a[href^=http] attr{href} 
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] attr{href}
$ curl -L -s reddit.com/r/programming/ |  
pup p.title a[href^=http] attr{href} 
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] attr{href}
$ curl -L -s reddit.com/r/programming/ |  
pup p.title a[href^=http] attr{href} 
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] attr{href}
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] json{} 
[ 
{ 
"attrs": { 
"href": "https://hacks.mozilla.org/2014/10/passwordless-authentication- 
secure-simple-and-fast-to-deploy/" 
}, 
... 
]
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] json{} 
[ 
{ 
"attrs": { 
"href": "https://hacks.mozilla.org/2014/10/passwordless-authentication- 
secure-simple-and-fast-to-deploy/" 
}, 
... 
]
$ curl -s https://news.ycombinator.com/ |  
pup td.title a[href^=http] json{} 
[ 
{ 
"attrs": { 
"href": "https:.../" 
}, 
"tag": "a", 
"text": "SHOW HN: pup" 
}, 
... 
]
github.com/EricChiang/pup
Part II: 
Building CLI 
tools in Go
import java.util.Scanner; 
class Hello { 
public static void main(String[] args) { 
Scanner reader = new Scanner(System.in); 
System.out.print("Enter your name: "); 
String name = reader.nextLine(); 
System.out.printf("Hello, "+name+"!"); 
} 
}
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
import java.util.Scanner; 
class Hello { 
public static void main(String[] args) { 
Scanner reader = new Scanner(System.in); 
System.out.print("Enter your name: "); 
String name = reader.nextLine(); 
System.out.printf("Hello, "+name+"!"); 
} 
}
import java.util.Scanner; 
class Hello { 
public static void main(String[] args) { 
Scanner reader = new Scanner(System.in); 
System.out.print("Enter your name: "); 
String name = reader.nextLine(); 
System.out.printf("Hello, "+name+"!"); 
} 
}
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
import java.util.Scanner; 
class Hello { 
public static void main(String[] args) { 
Scanner reader = new Scanner(System.in); 
System.out.print("Enter your name: "); 
String name = reader.nextLine(); 
System.out.printf("Hello, "+name+"!"); 
} 
}
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Why 
Go?
Why 
not?
Taken from Rob Pike’s talk public static void main (2012)
“dear god make it stop” 
Taken from Rob Pike’s talk public static void main (2012)
Why 
not?
Why 
not?
I suck at 
this -->
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Go
package main 
import "fmt" 
func main() { 
fmt.Println("Hello, world!") 
}
line
package main 
import "io" 
import "os" 
func main() { 
io.Copy(os.Stdout, os.Stdin) 
io.WriteString(os.Stdout, "n") 
}
package main 
import "io" 
import "os" 
func main() { 
io.Copy(os.Stdout, os.Stdin) 
io.WriteString(os.Stdout, "n") 
}
package main 
import "io" 
import "os" 
func main() { 
io.Copy(os.Stdout, os.Stdin) 
io.WriteString(os.Stdout, "n") 
}
package main 
import "io" 
import "os" 
func main() { 
io.Copy(os.Stdout, os.Stdin) 
io.WriteString(os.Stdout, "n") 
}
package main 
import "io" 
import "os" 
func main() { 
io.Copy(os.Stdout, os.Stdin) 
io.WriteString(os.Stdout, "n") 
}
$ echo "Hello, World" 
Hello, World
$ echo "Hello, World" 
Hello, World 
$ go get github.com/ericchiang/line
$ echo "Hello, World" 
Hello, World 
$ go get github.com/ericchiang/line 
$ echo "Hello, World" | line 
Hello, World 
$
url-encode
Live demo!
gox
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Messing 
with zip
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line
Thanks!
1 of 158

Recommended

10 tips for making Bash a sane programming language by
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming languageYaroslav Tkachenko
764 views20 slides
Parsing JSON with a single regex by
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
34.7K views22 slides
R版Getopt::Longを作ってみた by
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたTakeshi Arabiki
3K views41 slides
7. Lower upper in Laravel by
7. Lower upper in Laravel7. Lower upper in Laravel
7. Lower upper in LaravelRazvan Raducanu, PhD
32 views5 slides
Perl Bag of Tricks - Baltimore Perl mongers by
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
2.3K views26 slides
Bag of tricks by
Bag of tricksBag of tricks
Bag of tricksbrian d foy
4.4K views32 slides

More Related Content

What's hot

Ruby 1.9 by
Ruby 1.9Ruby 1.9
Ruby 1.9guestaef7ea
913 views32 slides
Introduction to Perl by
Introduction to PerlIntroduction to Perl
Introduction to Perlworr1244
566 views38 slides
Unix 5 en by
Unix 5 enUnix 5 en
Unix 5 enSimonas Kareiva
381 views32 slides
Visualizing ORACLE performance data with R @ #C16LV by
Visualizing ORACLE performance data with R @ #C16LVVisualizing ORACLE performance data with R @ #C16LV
Visualizing ORACLE performance data with R @ #C16LVMaxym Kharchenko
1.7K views54 slides
Ethiopian multiplication in Perl6 by
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
2.1K views56 slides
Creating a keystroke logger in unix shell scripting by
Creating a keystroke logger in unix shell scriptingCreating a keystroke logger in unix shell scripting
Creating a keystroke logger in unix shell scriptingDan Morrill
11.9K views15 slides

What's hot(20)

Introduction to Perl by worr1244
Introduction to PerlIntroduction to Perl
Introduction to Perl
worr1244566 views
Visualizing ORACLE performance data with R @ #C16LV by Maxym Kharchenko
Visualizing ORACLE performance data with R @ #C16LVVisualizing ORACLE performance data with R @ #C16LV
Visualizing ORACLE performance data with R @ #C16LV
Maxym Kharchenko1.7K views
Creating a keystroke logger in unix shell scripting by Dan Morrill
Creating a keystroke logger in unix shell scriptingCreating a keystroke logger in unix shell scripting
Creating a keystroke logger in unix shell scripting
Dan Morrill11.9K views
201412 seccon2014 オンライン予選(英語) write-up by 恵寿 東
201412 seccon2014 オンライン予選(英語) write-up201412 seccon2014 オンライン予選(英語) write-up
201412 seccon2014 オンライン予選(英語) write-up
恵寿 東357 views
Mkscript sh by Ben Pope
Mkscript shMkscript sh
Mkscript sh
Ben Pope121 views
Windows power shell basics by Dan Morrill
Windows power shell basicsWindows power shell basics
Windows power shell basics
Dan Morrill1.1K views
Ch3(working with file) by Chhom Karath
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
Chhom Karath174 views
Windows power shell and active directory by Dan Morrill
Windows power shell and active directoryWindows power shell and active directory
Windows power shell and active directory
Dan Morrill1.8K views
Ten modules I haven't yet talked about by acme
Ten modules I haven't yet talked aboutTen modules I haven't yet talked about
Ten modules I haven't yet talked about
acme1.1K views
Rails 2010 Workshop by dtsadok
Rails 2010 WorkshopRails 2010 Workshop
Rails 2010 Workshop
dtsadok627 views
Process monitoring in UNIX shell scripting by Dan Morrill
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
Dan Morrill5.3K views
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012 by Amazon Web Services
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
Amazon Web Services11.6K views
Fewer cables by acme
Fewer cablesFewer cables
Fewer cables
acme1.4K views

Viewers also liked

Go for statistical programming by
Go for statistical programmingGo for statistical programming
Go for statistical programmingHakka Labs
12K views47 slides
Docker in Production: Reality, Not Hype by
Docker in Production: Reality, Not HypeDocker in Production: Reality, Not Hype
Docker in Production: Reality, Not Hypebridgetkromhout
1.6K views36 slides
Sometimes you feel like a docker... (NYC) by
Sometimes you feel like a docker... (NYC)Sometimes you feel like a docker... (NYC)
Sometimes you feel like a docker... (NYC)bridgetkromhout
681 views15 slides
Perl Introduction by
Perl IntroductionPerl Introduction
Perl IntroductionMarcos Rebelo
19.6K views137 slides
Introduction to Perl - Day 1 by
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
58.5K views141 slides
Come With Golang by
Come With GolangCome With Golang
Come With Golang尚文 曾
765 views38 slides

Viewers also liked(8)

Go for statistical programming by Hakka Labs
Go for statistical programmingGo for statistical programming
Go for statistical programming
Hakka Labs12K views
Docker in Production: Reality, Not Hype by bridgetkromhout
Docker in Production: Reality, Not HypeDocker in Production: Reality, Not Hype
Docker in Production: Reality, Not Hype
bridgetkromhout1.6K views
Sometimes you feel like a docker... (NYC) by bridgetkromhout
Sometimes you feel like a docker... (NYC)Sometimes you feel like a docker... (NYC)
Sometimes you feel like a docker... (NYC)
bridgetkromhout681 views
Introduction to Perl - Day 1 by Dave Cross
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
Dave Cross58.5K views
Come With Golang by 尚文 曾
Come With GolangCome With Golang
Come With Golang
尚文 曾765 views
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno by Nexus FrontierTech
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
Nexus FrontierTech708 views
Reference, Sense, and Referring Expression in Semantics by Ersa Dewana
Reference, Sense, and Referring Expression in SemanticsReference, Sense, and Referring Expression in Semantics
Reference, Sense, and Referring Expression in Semantics
Ersa Dewana35.5K views

Similar to Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line

Simple Ways To Be A Better Programmer (OSCON 2007) by
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Michael Schwern
971 views177 slides
Perl.Hacks.On.Vim by
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
107.6K views225 slides
Rack Middleware by
Rack MiddlewareRack Middleware
Rack MiddlewareLittleBIGRuby
2.4K views175 slides
Perl6 Regexen: Reduce the line noise in your code. by
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
322 views43 slides
BASH Variables Part 1: Basic Interpolation by
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationWorkhorse Computing
930 views73 slides
R57php 1231677414471772-2 by
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2ady36
1.8K views47 slides

Similar to Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line(20)

Simple Ways To Be A Better Programmer (OSCON 2007) by Michael Schwern
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
Michael Schwern971 views
Perl.Hacks.On.Vim by Lin Yo-An
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An107.6K views
Perl6 Regexen: Reduce the line noise in your code. by Workhorse Computing
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
R57php 1231677414471772-2 by ady36
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2
ady361.8K views
Unix command-line tools by Eric Wilson
Unix command-line toolsUnix command-line tools
Unix command-line tools
Eric Wilson45K views
Command by gajshield
CommandCommand
Command
gajshield246.7K views
Perl.Hacks.On.Vim Perlchina by guestcf9240
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
guestcf92401.1K views
AnyMQ, Hippie, and the real-time web by clkao
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao4K views
My First Rails Plugin - Usertext by frankieroberto
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertext
frankieroberto696 views
Modern Web Development with Perl by Dave Cross
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
Dave Cross32.3K views
Mining Ruby Gem vulnerabilities for Fun and No Profit. by Larry Cashdollar
Mining Ruby Gem vulnerabilities for Fun and No Profit.Mining Ruby Gem vulnerabilities for Fun and No Profit.
Mining Ruby Gem vulnerabilities for Fun and No Profit.
Larry Cashdollar438 views
Template Haskell とか by Hiromi Ishii
Template Haskell とかTemplate Haskell とか
Template Haskell とか
Hiromi Ishii2.1K views
Perl.Hacks.On.Vim Perlchina by Lin Yo-An
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
Lin Yo-An1.5K views
Good Evils In Perl (Yapc Asia) by Kang-min Liu
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu8.9K views
Os Fetterupdated by oscon2007
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
oscon2007245 views

More from Arc & Codementor

Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc by
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcRemote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcArc & Codementor
364 views31 slides
Introduction to Python for Data Science by
Introduction to Python for Data ScienceIntroduction to Python for Data Science
Introduction to Python for Data ScienceArc & Codementor
4.6K views25 slides
25 php interview questions – codementor by
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementorArc & Codementor
173.1K views37 slides
20 iOS developer interview questions by
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questionsArc & Codementor
2.3K views23 slides
29 Essential AngularJS Interview Questions by
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview QuestionsArc & Codementor
487.6K views31 slides
37 Java Interview Questions by
37 Java Interview Questions37 Java Interview Questions
37 Java Interview QuestionsArc & Codementor
20.8K views39 slides

More from Arc & Codementor(14)

Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc by Arc & Codementor
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcRemote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Arc & Codementor364 views
Introduction to Python for Data Science by Arc & Codementor
Introduction to Python for Data ScienceIntroduction to Python for Data Science
Introduction to Python for Data Science
Arc & Codementor4.6K views
25 php interview questions – codementor by Arc & Codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementor
Arc & Codementor173.1K views
20 iOS developer interview questions by Arc & Codementor
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questions
Arc & Codementor2.3K views
29 Essential AngularJS Interview Questions by Arc & Codementor
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions
Arc & Codementor487.6K views
21 Essential JavaScript Interview Questions by Arc & Codementor
21 Essential JavaScript Interview Questions21 Essential JavaScript Interview Questions
21 Essential JavaScript Interview Questions
Arc & Codementor653.5K views
Top 10 Programming Languages in 2015 by Arc & Codementor
Top 10 Programming Languages in 2015Top 10 Programming Languages in 2015
Top 10 Programming Languages in 2015
Arc & Codementor589 views
Angular meteor for angular devs by Arc & Codementor
Angular meteor for angular devsAngular meteor for angular devs
Angular meteor for angular devs
Arc & Codementor18.8K views
Introduction to Tmux - Codementor Tmux Office Hours Part 1 by Arc & Codementor
Introduction to Tmux - Codementor Tmux Office Hours Part 1Introduction to Tmux - Codementor Tmux Office Hours Part 1
Introduction to Tmux - Codementor Tmux Office Hours Part 1
Arc & Codementor42K views
Building Modern and Secure PHP Applications – Codementor Office Hours with Be... by Arc & Codementor
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Arc & Codementor11.2K views
Python Internals Optimization Choices Made - Codementors Office Hours with St... by Arc & Codementor
Python Internals Optimization Choices Made - Codementors Office Hours with St...Python Internals Optimization Choices Made - Codementors Office Hours with St...
Python Internals Optimization Choices Made - Codementors Office Hours with St...
Arc & Codementor20.3K views

Recently uploaded

Network Source of Truth and Infrastructure as Code revisited by
Network Source of Truth and Infrastructure as Code revisitedNetwork Source of Truth and Infrastructure as Code revisited
Network Source of Truth and Infrastructure as Code revisitedNetwork Automation Forum
27 views45 slides
MVP and prioritization.pdf by
MVP and prioritization.pdfMVP and prioritization.pdf
MVP and prioritization.pdfrahuldharwal141
31 views8 slides
virtual reality.pptx by
virtual reality.pptxvirtual reality.pptx
virtual reality.pptxG036GaikwadSnehal
14 views15 slides
Unit 1_Lecture 2_Physical Design of IoT.pdf by
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdfStephenTec
12 views36 slides
Evolving the Network Automation Journey from Python to Platforms by
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
13 views21 slides
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
18 views6 slides

Recently uploaded(20)

Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex10 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software280 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker40 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views

Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at the command-line

  • 1. stdin, stdout pup, Go & life at the command-line
  • 3. stdin, stdout pup, Go & life at the command-line
  • 5. $ cd ~/talks/codementor $ cat hello.txt Hello, Code Mentor! $
  • 20. data
  • 21. [LOG] some data [LOG] more data [LOG] even more
  • 23. { “some”: “data”, “more”: “data” }
  • 43. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 44. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 45. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 46. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 47. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 48. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 49. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 50. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 51. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 53. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 55. $ wget -O Shakespeare.txt http://gutenberg.org/cache/epub/100/pg100.txt
  • 56. $ wget -O Shakespeare.txt http://gutenberg.org/cache/epub/100/pg100.txt
  • 57. $ wget -O Shakespeare.txt http://gutenberg.org/cache/epub/100/pg100.txt
  • 59. $ wget --load-cookies cookies.txt
  • 63. $ wget -O Shakespeare.txt http://gutenberg.org/cache/epub/100/pg100.txt
  • 64. $ curl -o Shakespeare.txt http://gutenberg.org/cache/epub/100/pg100.txt
  • 65. $ cat Shakespeare.txt | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 66. $ curl http://gutenberg.org... | sed -e 's/s+/n/g' | tr -d ' ' | grep -e '^$' -v | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr | head -n 50
  • 73. “Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp.”
  • 74. “Have you tried using an XML parser instead?”
  • 75. But it gets worse
  • 76. <tbody> <tr><img src="foo"></tr> <tr><img/><br> </tbody> </table>
  • 77. Yes, this is valid HTML: <tbody> <tr><img src="foo"></tr> <tr><img/><br> </tbody> </table>
  • 78. Yes, this is valid HTML: <tbody> <tr><img src="foo"></tr> <tr><img/><br> </tbody> </table>
  • 79. Yes, this is valid HTML: <tbody> <tr><img src="foo"></tr> <tr><img/><br> </tbody> </table>
  • 80. Yes, this is valid HTML: <tbody> <tr><img src="foo"></tr> <tr><img/><br> </tbody> </table>
  • 83. NEVER TRY TO WRITE AN HTML PARSER
  • 87. pup
  • 111. $ curl -L -s reddit.com/r/programming/ | pup p.title a[href^=http] attr{href} $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] attr{href}
  • 112. $ curl -L -s reddit.com/r/programming/ | pup p.title a[href^=http] attr{href} $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] attr{href}
  • 113. $ curl -L -s reddit.com/r/programming/ | pup p.title a[href^=http] attr{href} $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] attr{href}
  • 114. $ curl -L -s reddit.com/r/programming/ | pup p.title a[href^=http] attr{href} $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] attr{href}
  • 115. $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] json{} [ { "attrs": { "href": "https://hacks.mozilla.org/2014/10/passwordless-authentication- secure-simple-and-fast-to-deploy/" }, ... ]
  • 116. $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] json{} [ { "attrs": { "href": "https://hacks.mozilla.org/2014/10/passwordless-authentication- secure-simple-and-fast-to-deploy/" }, ... ]
  • 117. $ curl -s https://news.ycombinator.com/ | pup td.title a[href^=http] json{} [ { "attrs": { "href": "https:.../" }, "tag": "a", "text": "SHOW HN: pup" }, ... ]
  • 119. Part II: Building CLI tools in Go
  • 120. import java.util.Scanner; class Hello { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter your name: "); String name = reader.nextLine(); System.out.printf("Hello, "+name+"!"); } }
  • 122. import java.util.Scanner; class Hello { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter your name: "); String name = reader.nextLine(); System.out.printf("Hello, "+name+"!"); } }
  • 123. import java.util.Scanner; class Hello { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter your name: "); String name = reader.nextLine(); System.out.printf("Hello, "+name+"!"); } }
  • 125. import java.util.Scanner; class Hello { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter your name: "); String name = reader.nextLine(); System.out.printf("Hello, "+name+"!"); } }
  • 130. Taken from Rob Pike’s talk public static void main (2012)
  • 131. “dear god make it stop” Taken from Rob Pike’s talk public static void main (2012)
  • 134. I suck at this -->
  • 136. Go
  • 137. package main import "fmt" func main() { fmt.Println("Hello, world!") }
  • 138. line
  • 139. package main import "io" import "os" func main() { io.Copy(os.Stdout, os.Stdin) io.WriteString(os.Stdout, "n") }
  • 140. package main import "io" import "os" func main() { io.Copy(os.Stdout, os.Stdin) io.WriteString(os.Stdout, "n") }
  • 141. package main import "io" import "os" func main() { io.Copy(os.Stdout, os.Stdin) io.WriteString(os.Stdout, "n") }
  • 142. package main import "io" import "os" func main() { io.Copy(os.Stdout, os.Stdin) io.WriteString(os.Stdout, "n") }
  • 143. package main import "io" import "os" func main() { io.Copy(os.Stdout, os.Stdin) io.WriteString(os.Stdout, "n") }
  • 144. $ echo "Hello, World" Hello, World
  • 145. $ echo "Hello, World" Hello, World $ go get github.com/ericchiang/line
  • 146. $ echo "Hello, World" Hello, World $ go get github.com/ericchiang/line $ echo "Hello, World" | line Hello, World $
  • 149. gox

Editor's Notes

  1. Hi there. I’m a founding member and software engineer here. Come check us out!
  2. Big data… dude.
  3. This is what data can look like. Just a log from some process.
  4. Or a csv from an excell spreadsheet.
  5. Sometimes (if you’re lucky) data looks like this.
  6. Some data looks like this
  7. But the stand out command here is actually the pipe. It’s allowing us to string together a tone of other commands.
  8. On of my favorite uses of wget, is combining it with my session cookies. All of a sudden, the data I’m trying to
  9. But the stand out command here is actually the pipe. It’s allowing us to string together a tone of other commands.
  10. No, but really.
  11. One of the most popular answers ever on stackoverflow
  12. Okay let’s start with the trivial. <img> tags never have closing tags but can sometimes have slashes before their last brace.
  13. But what about <tr>? Did you know that the last closing tag is optional in many circumstances?
  14. An yeah, that’s not me cutting off the top of the HTML code. The opening <table> is optional depending on the context.
  15. Ouch. So much for our XML parser.
  16. Ouch. So much for our XML parser.
  17. There are some things you should never build yourself. And along with CAPCHAs (https://github.com/mieko/sr-captcha/blob/gh-pages/index.md), HTML parsers are among them.
  18. We need more pipes!
  19. With the success of pup, I’d like to introduce you to my newest command line creation.
  20. I learned how to program in college.
  21. This is what this program does. It prompts the user for some input, then
  22. Stdin, stdout, and stderr.
  23. This is what this program does. It prompts the user for some input, then
  24. This is what this program does. It prompts the user for some input, then
  25. With the success of pup, I’d like to introduce you to my newest command line creation.
  26. With the success of pup, I’d like to introduce you to my newest command line creation.
  27. With the success of pup, I’d like to introduce you to my newest command line creation.
  28. With the success of pup, I’d like to introduce you to my newest command line creation.