SlideShare a Scribd company logo
1 of 45
Rubish: A Quixotic Shell

       Howard Yeh
Quix.ot.ic
• kwik-’sä-tik
• foolishly impractical especially in the pursuit
  of ideals ; especially : marked by rash lofty
  romantic ideas or extravagantly chivalrous
  action.
Why Do You Care?
• Closes the gap between script and shell
• Object-Oriented Meta-shell (frobbable)
• Extensible
  – Namespace
  – Local extensions (with singleton objects)
  – Abstraction as codified memory
• Ruby you know and love
Symbiosis With Ruby
•   Meta access
•   Data type
•   Plausibly concise syntax
•   Object#instance_eval(&block)
•   Rubish has no metasyntax
•   Rubish uses no monkey patches
    – Not strictly true, but…
Introduction to Rubish

   abandon bash all ye who enters…
Overview
• Executable
  – Command, Pipe
  – Sed, Awk
  – Batch
• Job Control
  – Concurrency; Exception Mechanism
• Context
  – Dynamically scoped IO; Workspace
Command
Rubish                         Bash
foo                            foo
foo :abc                       foo -abc
foo “a b c”                    foo a b c
foo.q “a b c”                  foo “a b c”
foo “a”, “b”, “c”
foo [quot;aquot;,quot;bquot;,quot;cquot;]
foo [[quot;aquot;,quot;bquot;],quot;cquot;,quot;dquot;]

Handling weird filenames
rsh> touch(quot;a bquot;,quot;c dquot;).q
rsh> wc(ls.map).q
Pipe
• Build pipe with factory
rsh> p { cmd1; cmd2; cmd3 }

• Build pipe from array of commands
rsh> @cmds = [cmd1,cmd2,cmd3]
rsh> p(@cmds)
IO Redirection
• Methods defined on the Executable class
  – Executable#{i,o,err}
  – Common API to all subclasses
  – So far only supports stdin, stdout, stderr
• With File
• With Ruby IO object
• With a block that receives a pipe
  – Good for building further abstractions
IO to File
rsh> cat.o(quot;outputquot;)
a
b
c
^D
rsh> wc(quot;outputquot;).first.to_i
3
IO with Block
rsh> @c = cat.i {|pipe| pipe.puts 1,2,3 }
rsh> @c
1
2
3
# ask the command to write to a pipe instead
rsh> @c.o { |pipe| ... }
IO Abstractions
• Enumerating methods
  – Common API to all Executable subclasses
  – Executable#{each,map}
  – Executable#{head(n=1),tail(n=1),first,last}
• Implemented with the Rubish IO architecture.
  – OOP for the win!
Executable#each!

def each!
  self.o do |pipe|
   pipe.each_line do |line|
     line.chomp!
     yield(line)
   end
  end
  job = self.exec!
  return job
 end
Processing with Ruby
# array of listed file names
ls.map
# last file as string
ls.last # == ls.tail(1).first
# extension name of last 10 files
ls.tail(10) {|f| File.extname(f) }
# ditto with pipe
p { …}.map {|line| … }
Awk & Sed
Sed “One-Liner”
• Courtesy J. Zawinsky (Unix Hater Handbook)
# find *.el files that didn't have corresponding *.elc files
# only two processes per file.
sh> find . -name ’*.el’ -print 
| sed ’s/^/FOO=/’|
sed ’s/$/; if * ! -f  ${FOO}c ]; then 
echo  $FOO ; fi/’ | sh


• Rubish Sed
rsh> find(quot;. -name '*.el'quot;).sed { p if !File.exist?(line + quot;cquot;) }
rsh> find(quot;. -name '*.el'quot;).sed { p if !File.exist?(line + quot;cquot;) }.map {|f| … }
Awk & Sed
•   Unix Powertools are for Powerfools
•   Hard to predict complexity.
•   Hard to get right.
•   Hard to remember.
•   Hard to extend.
•   Hard to generalize.
    – “weird chars” problem
Rubish Sed & Awk
• Doesn’t aim for full generality
  – Since we are embedded in Ruby anyway
• Captures common usage patterns
  – Common-Lisp loopesque helpers
• Be explicit
  – Sed does not print by default
• Fits well
  – Both are subclasses of Executable
grep with context (Sed)


# grep -A1 -B1
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
grep with context (Rubish)
# rubish sed
sed {
  if line =~ /regexp/
    p quot;====quot;
    # special case if the first line matches
    p prev if respond_to?(:prev)
    p
    p peek(1)
  end
  hold(:prev,1,line) # dynamically creates a method “prev”
}
Streamer
• Awk and Sed are subclasses of Streamer
• Streamer#{peek(n=1),skip(n=1)}
  – No more sedistic register shufflings
• Streamer#{max,min,count,collect,…}
  – Common usage patterns
• Streamer#{quit,stop}
• Streamer#{each,map,head,tail,…}
  – Inherited methods from Executable
grep with context (Rubish)
rsh> cat.i {|p| p.puts((1..11).to_a)}.sed { ... }
====
1
2
====
9
10
11
====
10
11
grep with context (Rubish)
• Easy to generalize
# simulates ‘grep regexp -Aa -Bb’
sed {
  if line =~ regexp
    p quot;====quot;
    # special case if the first line matches
    p prev if respond_to?(:prev)
    p
    p peek(a)
  end
  hold(:prev,b,line)
}
Aggregator
• Streamer#{max,min,count,collect,…}
  – Capture common usage patterns
  – Inspired by Common Lisp’s Loop Facility
  – Method signature: helper(name,value,key)
• Aggregation partitioned by key
  – nil is the special global key under which everything
    is aggregated.
Aggregator
# longest and shortest filename lengths
rsh> ls.awk {
   max(:mx,line)
   min(:mn,line)
 }.end {[mx,mn]}
[25, 3]
Aggregator
rsh> ls.awk { f=a[0]; collect(:fn,f,File.extname(f))}.end { fn}
{quot;quot;=> [quot;aquot;,...,quot;utilquot;],
  quot;.gzquot;=>[quot;ruby-termios-0.9.5.tar.gzquot;],
  quot;.ymlquot;=>[quot;VERSION.ymlquot;],
  quot;.shquot;=>[quot;test.shquot;],
  quot;.outputquot;=>[quot;awk.outputquot;],
  quot;.5quot;=>[quot;ruby-termios-0.9.5quot;],
  quot;.textilequot;=>[quot;README.textilequot;],
  quot;.rbquot;=>[quot;address.rbquot;, quot;foo.rbquot;, quot;my.rbquot;],
  quot;.barquot;=>[quot;foo.barquot;]
  nil=>[quot;aquot;, ...,quot;VERSION.ymlquot;]}
# fn(“.rb”) contains the array of *.rb
Addressed Patterns
.sed(3) { … } # triggered for line 3
.sed(3,9) { … } # lines 3 to 9 inclusive
.sed(3,:eof) { … } # lines 3 to end of file
.sed(/a/) { … } # triggered for matching lines
.sed(/a/,/b/) # triggered for lines between
# ditto for awk
.awk(/a/,/b/)
Rubish Concurrency
Concurrency
• Coarse Grained
  – For independent tasks
• No interaction between tasks
  – No deadlock
  – No shared memory (by abstinence)
  – But is safety by policy (read: no safety)
• Ruby Green Thread
  – You could always fork… I guess?
Background Jobs
• Executable#{exec!,each!,map!}
  – #exec! returns an instance of Job
  – #each! invokes the iterator in a background thread
  – #map!(acc) << into an (hopefully thread safe)
    accumulator.
• Job#{wait,stop}
  – #wait returns the result of a job after it completes
  – #stop signal a job to terminate, then wait
• For Command,Pipe,Sed,Awk, and more.
Background Jobs
# returns immediately
rsh> @job = slowcat(3).exec!
rsh> jobs # == [@job]
# slowcat(3) takes 3 seconds to complete
rsh> waitall # after 3 seconds => @job.wait

rsh> @acc = [] # should use a thread-safe acc
rsh> ls.map!(@acc)
rsh> ls.map!(@acc)
Exception Handling
• Job#wait would raise on abnormal completion
   – exitstatus != 0
• Exception avoids error checking cruft
   – It’s the 21st century!
• A little suprising
   – grep quot;notfound *quot;
   – wc a-directory
Rubish in Context
Context
• Encapsulates IOs
  – Dynamically scoped
• Encapsulates Bindings
  – Lexically scoped
  – Namespace management
  – Local extensibility
• A context defines the meaning of a closure
  with free bindings.
Context-Sensitive Block
• Object#instance_eval(&block)
obj.instance_eval {
  binding1
  binding2
}
• Local extensibility
obj.extend(module).instance_eval { … }
Context IO
with {
  cmd1.exec
  cmd2.exec
  with { cmd3 }.o(quot;output3quot;).exec
}.o(quot;output1-2quot;).exec
Context Extension
# ad hoc, local extensions
with(derive({def foo; ...; end})) {
  ... # outer foo
  with(derive({def foo; ...; end})) {
    ... #inner foo
  }
  ... # outer foo
}
Context Extension with Modules
# prebaked (modules from ‘load’)
with(derive(mod1,mod2)) {
  …
}
Batch
• A batch job is a contextualized block executed
  in a thread.
• Schematically :
@job = Thread.new { context.eval { … }}
@job.wait
• Similar to subshell, but in the same process
• A Batch is also an Executable!
Batch
# first extend context
# then carry out a block within a batch thread
batch(derive(...)) { ... }

# all Executable methods apply
@job = batch(derive(...)) { ... }.exec!
batch(derive(...)) { ... }.map
batch(derive(...)) { ... }.awk
…
Structured Concurrency
# Concurrent Jobs arranged in a tree:
batch {
  exec! cmd1, cmd2
  batch {
    exec! cmd3, cmd4
    batch { exec! cmd5 }
  }.exec # we’ll wait till this batch completes
  …
}.exec!
Conclusion
• OOP is great!
    – Inheritance makes code confusing
    – Polymorphism is powerful
    – Excellent namespace management
•   Design by Symbiosis
•   Singleton objects for local extensibility
•   Object#instance_eval(&block)
•   Metaprogramming
    – Make things frobbable
    – I don’t miss lisp that much…
Thank You
• http://github.com/hayeah/rubish/tree/master
  – Need lots more work.
  – Generalize Rubish for remote scripting.
• Looking for interesting projects
  – I like weird languages.


• hayeah@gmail.com

More Related Content

What's hot

Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Cloudflare
 
mruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしmruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしHiroshi SHIBATA
 
Advanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.jsAdvanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.jsStefan Baumgartner
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxSignalFx
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0Tim Bunce
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to GoCloudflare
 
Otimizando Aplicações em Rails
Otimizando Aplicações em RailsOtimizando Aplicações em Rails
Otimizando Aplicações em RailsJuan Maiz
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyTim Bunce
 
Php assíncrono com_react_php
Php assíncrono com_react_phpPhp assíncrono com_react_php
Php assíncrono com_react_phpRenato Lucena
 
Будь первым
Будь первымБудь первым
Будь первымFDConf
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12Tim Bunce
 
Roll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaRoll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaJon Moore
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder RubyNick Sieger
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talkLocaweb
 

What's hot (20)

Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
 
mruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしmruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなし
 
Advanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.jsAdvanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.js
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Go Memory
Go MemoryGo Memory
Go Memory
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
ZSH and RVM
ZSH and RVMZSH and RVM
ZSH and RVM
 
Otimizando Aplicações em Rails
Otimizando Aplicações em RailsOtimizando Aplicações em Rails
Otimizando Aplicações em Rails
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.key
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Php assíncrono com_react_php
Php assíncrono com_react_phpPhp assíncrono com_react_php
Php assíncrono com_react_php
 
Будь первым
Будь первымБудь первым
Будь первым
 
RingoJS
RingoJSRingoJS
RingoJS
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12
 
Roll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaRoll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and Lua
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talk
 

Viewers also liked

Definition to ecology wiki
Definition to ecology wikiDefinition to ecology wiki
Definition to ecology wikij_millard
 
Unit 5 Day 8 Biomes Ppt
Unit 5 Day 8 Biomes PptUnit 5 Day 8 Biomes Ppt
Unit 5 Day 8 Biomes Pptguest25347f
 
Ess Topic 5.1 The Nature of Pollution
Ess Topic 5.1   The Nature of PollutionEss Topic 5.1   The Nature of Pollution
Ess Topic 5.1 The Nature of PollutionBrad Kremer
 
Air pollution: source, effect and cont
Air pollution: source, effect and contAir pollution: source, effect and cont
Air pollution: source, effect and contAnas Indabawa
 
Industrial pollution
Industrial pollutionIndustrial pollution
Industrial pollutionYashas Anur
 

Viewers also liked (11)

Definition to ecology wiki
Definition to ecology wikiDefinition to ecology wiki
Definition to ecology wiki
 
Biogeocycles
BiogeocyclesBiogeocycles
Biogeocycles
 
Environmental Pollution
Environmental PollutionEnvironmental Pollution
Environmental Pollution
 
education
educationeducation
education
 
Unit 5 Day 8 Biomes Ppt
Unit 5 Day 8 Biomes PptUnit 5 Day 8 Biomes Ppt
Unit 5 Day 8 Biomes Ppt
 
Ess Topic 5.1 The Nature of Pollution
Ess Topic 5.1   The Nature of PollutionEss Topic 5.1   The Nature of Pollution
Ess Topic 5.1 The Nature of Pollution
 
Air pollution: source, effect and cont
Air pollution: source, effect and contAir pollution: source, effect and cont
Air pollution: source, effect and cont
 
LAND POLLUTION
LAND POLLUTIONLAND POLLUTION
LAND POLLUTION
 
Industrial pollution
Industrial pollutionIndustrial pollution
Industrial pollution
 
Sewerage System
Sewerage SystemSewerage System
Sewerage System
 
Noise Pollution
Noise PollutionNoise Pollution
Noise Pollution
 

Similar to Rubish- A Quixotic Shell

JSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederChristoph Pickl
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
javascript teach
javascript teachjavascript teach
javascript teachguest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_Whiteguest3732fa
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介Wen-Tien Chang
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9tomaspavelka
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de RailsFabio Akita
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them Allegypt
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
Umleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appUmleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appLenz Gschwendtner
 

Similar to Rubish- A Quixotic Shell (20)

JSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael Greifeneder
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
MySQL Proxy tutorial
MySQL Proxy tutorialMySQL Proxy tutorial
MySQL Proxy tutorial
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Umleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB appUmleitung: a tiny mochiweb/CouchDB app
Umleitung: a tiny mochiweb/CouchDB app
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Rubish- A Quixotic Shell

  • 1. Rubish: A Quixotic Shell Howard Yeh
  • 2. Quix.ot.ic • kwik-’sä-tik • foolishly impractical especially in the pursuit of ideals ; especially : marked by rash lofty romantic ideas or extravagantly chivalrous action.
  • 3.
  • 4. Why Do You Care? • Closes the gap between script and shell • Object-Oriented Meta-shell (frobbable) • Extensible – Namespace – Local extensions (with singleton objects) – Abstraction as codified memory • Ruby you know and love
  • 5. Symbiosis With Ruby • Meta access • Data type • Plausibly concise syntax • Object#instance_eval(&block) • Rubish has no metasyntax • Rubish uses no monkey patches – Not strictly true, but…
  • 6. Introduction to Rubish abandon bash all ye who enters…
  • 7. Overview • Executable – Command, Pipe – Sed, Awk – Batch • Job Control – Concurrency; Exception Mechanism • Context – Dynamically scoped IO; Workspace
  • 8. Command Rubish Bash foo foo foo :abc foo -abc foo “a b c” foo a b c foo.q “a b c” foo “a b c” foo “a”, “b”, “c” foo [quot;aquot;,quot;bquot;,quot;cquot;] foo [[quot;aquot;,quot;bquot;],quot;cquot;,quot;dquot;] Handling weird filenames rsh> touch(quot;a bquot;,quot;c dquot;).q rsh> wc(ls.map).q
  • 9. Pipe • Build pipe with factory rsh> p { cmd1; cmd2; cmd3 } • Build pipe from array of commands rsh> @cmds = [cmd1,cmd2,cmd3] rsh> p(@cmds)
  • 10. IO Redirection • Methods defined on the Executable class – Executable#{i,o,err} – Common API to all subclasses – So far only supports stdin, stdout, stderr • With File • With Ruby IO object • With a block that receives a pipe – Good for building further abstractions
  • 11. IO to File rsh> cat.o(quot;outputquot;) a b c ^D rsh> wc(quot;outputquot;).first.to_i 3
  • 12. IO with Block rsh> @c = cat.i {|pipe| pipe.puts 1,2,3 } rsh> @c 1 2 3 # ask the command to write to a pipe instead rsh> @c.o { |pipe| ... }
  • 13. IO Abstractions • Enumerating methods – Common API to all Executable subclasses – Executable#{each,map} – Executable#{head(n=1),tail(n=1),first,last} • Implemented with the Rubish IO architecture. – OOP for the win!
  • 14. Executable#each! def each! self.o do |pipe| pipe.each_line do |line| line.chomp! yield(line) end end job = self.exec! return job end
  • 15. Processing with Ruby # array of listed file names ls.map # last file as string ls.last # == ls.tail(1).first # extension name of last 10 files ls.tail(10) {|f| File.extname(f) } # ditto with pipe p { …}.map {|line| … }
  • 17. Sed “One-Liner” • Courtesy J. Zawinsky (Unix Hater Handbook) # find *.el files that didn't have corresponding *.elc files # only two processes per file. sh> find . -name ’*.el’ -print | sed ’s/^/FOO=/’| sed ’s/$/; if * ! -f ${FOO}c ]; then echo $FOO ; fi/’ | sh • Rubish Sed rsh> find(quot;. -name '*.el'quot;).sed { p if !File.exist?(line + quot;cquot;) } rsh> find(quot;. -name '*.el'quot;).sed { p if !File.exist?(line + quot;cquot;) }.map {|f| … }
  • 18. Awk & Sed • Unix Powertools are for Powerfools • Hard to predict complexity. • Hard to get right. • Hard to remember. • Hard to extend. • Hard to generalize. – “weird chars” problem
  • 19. Rubish Sed & Awk • Doesn’t aim for full generality – Since we are embedded in Ruby anyway • Captures common usage patterns – Common-Lisp loopesque helpers • Be explicit – Sed does not print by default • Fits well – Both are subclasses of Executable
  • 20. grep with context (Sed) # grep -A1 -B1 sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
  • 21. grep with context (Rubish) # rubish sed sed { if line =~ /regexp/ p quot;====quot; # special case if the first line matches p prev if respond_to?(:prev) p p peek(1) end hold(:prev,1,line) # dynamically creates a method “prev” }
  • 22. Streamer • Awk and Sed are subclasses of Streamer • Streamer#{peek(n=1),skip(n=1)} – No more sedistic register shufflings • Streamer#{max,min,count,collect,…} – Common usage patterns • Streamer#{quit,stop} • Streamer#{each,map,head,tail,…} – Inherited methods from Executable
  • 23. grep with context (Rubish) rsh> cat.i {|p| p.puts((1..11).to_a)}.sed { ... } ==== 1 2 ==== 9 10 11 ==== 10 11
  • 24. grep with context (Rubish) • Easy to generalize # simulates ‘grep regexp -Aa -Bb’ sed { if line =~ regexp p quot;====quot; # special case if the first line matches p prev if respond_to?(:prev) p p peek(a) end hold(:prev,b,line) }
  • 25. Aggregator • Streamer#{max,min,count,collect,…} – Capture common usage patterns – Inspired by Common Lisp’s Loop Facility – Method signature: helper(name,value,key) • Aggregation partitioned by key – nil is the special global key under which everything is aggregated.
  • 26. Aggregator # longest and shortest filename lengths rsh> ls.awk { max(:mx,line) min(:mn,line) }.end {[mx,mn]} [25, 3]
  • 27. Aggregator rsh> ls.awk { f=a[0]; collect(:fn,f,File.extname(f))}.end { fn} {quot;quot;=> [quot;aquot;,...,quot;utilquot;], quot;.gzquot;=>[quot;ruby-termios-0.9.5.tar.gzquot;], quot;.ymlquot;=>[quot;VERSION.ymlquot;], quot;.shquot;=>[quot;test.shquot;], quot;.outputquot;=>[quot;awk.outputquot;], quot;.5quot;=>[quot;ruby-termios-0.9.5quot;], quot;.textilequot;=>[quot;README.textilequot;], quot;.rbquot;=>[quot;address.rbquot;, quot;foo.rbquot;, quot;my.rbquot;], quot;.barquot;=>[quot;foo.barquot;] nil=>[quot;aquot;, ...,quot;VERSION.ymlquot;]} # fn(“.rb”) contains the array of *.rb
  • 28. Addressed Patterns .sed(3) { … } # triggered for line 3 .sed(3,9) { … } # lines 3 to 9 inclusive .sed(3,:eof) { … } # lines 3 to end of file .sed(/a/) { … } # triggered for matching lines .sed(/a/,/b/) # triggered for lines between # ditto for awk .awk(/a/,/b/)
  • 30. Concurrency • Coarse Grained – For independent tasks • No interaction between tasks – No deadlock – No shared memory (by abstinence) – But is safety by policy (read: no safety) • Ruby Green Thread – You could always fork… I guess?
  • 31. Background Jobs • Executable#{exec!,each!,map!} – #exec! returns an instance of Job – #each! invokes the iterator in a background thread – #map!(acc) << into an (hopefully thread safe) accumulator. • Job#{wait,stop} – #wait returns the result of a job after it completes – #stop signal a job to terminate, then wait • For Command,Pipe,Sed,Awk, and more.
  • 32. Background Jobs # returns immediately rsh> @job = slowcat(3).exec! rsh> jobs # == [@job] # slowcat(3) takes 3 seconds to complete rsh> waitall # after 3 seconds => @job.wait rsh> @acc = [] # should use a thread-safe acc rsh> ls.map!(@acc) rsh> ls.map!(@acc)
  • 33. Exception Handling • Job#wait would raise on abnormal completion – exitstatus != 0 • Exception avoids error checking cruft – It’s the 21st century! • A little suprising – grep quot;notfound *quot; – wc a-directory
  • 35. Context • Encapsulates IOs – Dynamically scoped • Encapsulates Bindings – Lexically scoped – Namespace management – Local extensibility • A context defines the meaning of a closure with free bindings.
  • 36. Context-Sensitive Block • Object#instance_eval(&block) obj.instance_eval { binding1 binding2 } • Local extensibility obj.extend(module).instance_eval { … }
  • 37. Context IO with { cmd1.exec cmd2.exec with { cmd3 }.o(quot;output3quot;).exec }.o(quot;output1-2quot;).exec
  • 38. Context Extension # ad hoc, local extensions with(derive({def foo; ...; end})) { ... # outer foo with(derive({def foo; ...; end})) { ... #inner foo } ... # outer foo }
  • 39. Context Extension with Modules # prebaked (modules from ‘load’) with(derive(mod1,mod2)) { … }
  • 40. Batch • A batch job is a contextualized block executed in a thread. • Schematically : @job = Thread.new { context.eval { … }} @job.wait • Similar to subshell, but in the same process • A Batch is also an Executable!
  • 41. Batch # first extend context # then carry out a block within a batch thread batch(derive(...)) { ... } # all Executable methods apply @job = batch(derive(...)) { ... }.exec! batch(derive(...)) { ... }.map batch(derive(...)) { ... }.awk …
  • 42. Structured Concurrency # Concurrent Jobs arranged in a tree: batch { exec! cmd1, cmd2 batch { exec! cmd3, cmd4 batch { exec! cmd5 } }.exec # we’ll wait till this batch completes … }.exec!
  • 44. • OOP is great! – Inheritance makes code confusing – Polymorphism is powerful – Excellent namespace management • Design by Symbiosis • Singleton objects for local extensibility • Object#instance_eval(&block) • Metaprogramming – Make things frobbable – I don’t miss lisp that much…
  • 45. Thank You • http://github.com/hayeah/rubish/tree/master – Need lots more work. – Generalize Rubish for remote scripting. • Looking for interesting projects – I like weird languages. • hayeah@gmail.com

Editor's Notes

  1. FoobarVerySurprisingDon’;t you think??Why, but why, would I want to say that?FoobarVerySurprisingDon’;t you think??Why, but why, would I want to say that?FoobarVerySurprisingDon’;t you think??Why, but why, would I want to say that?FoobarVerySurprisingDon’;t you think??Why, but why, would I want to say that?
  2. Concurrent safety is