

Bringing the best of Bash scripting to Ruby - astro-
http://radek.io/2015/07/13/ruby-scripting/

======
bmir-alum-007
The script I use to disable/enable dnscrypt-proxy (multiple instances behind
dnsmasq for HA)
[https://gist.github.com/steakknife/bf6967e2298b95da29b7](https://gist.github.com/steakknife/bf6967e2298b95da29b7)

Sample output (tethering):

    
    
        0 ~ git:master ❯❯❯ internet_access                                                                            
        Bluetooth DUN:  Bluetooth-Modem  dns 127.0.0.1
        Ethernet:  en0  macaddr xx:xx:xx:...:xx  dns 127.0.0.1
        FireWire:  fw0  dns 127.0.0.1
        Wi-Fi:  en1  macaddr xx:xx:xx:...:xx  dns 127.0.0.1
        iPhone USB:  en4  172.20.10.3/24  router 172.20.10.2  macaddr xx:xx:xx:...:xx dns 127.0.0.1
        Bluetooth PAN:  en3  dns 127.0.0.1
        Thunderbolt Bridge:  bridge0  dns 127.0.0.1
        0 ~ git:master ❯❯❯
    

Sample output (wifi enable, unassociated, no tethering):

    
    
        0 ~ git:master ❯❯❯ internet_access                                                                              
        1 ~ git:master ❯❯❯
    

This is driven by a non-privileged infinite looping event bash scripts which
TCP connects to another pair of bash scripts running as root which can
actually make the change because they're listening on two localhost tcp ports.

(I've tried these other event-based app/script utilities and they're fragile
and buggy as heck.)

It seems like something Apple, for one, should take on... deprecate
AppleScript and use something more common, accessible and make a common,
standardized scripting platform far more comprehensively documented in
something like Ruby. AppleScript is just too COBOL/Cucumber "English" and
poorly documented to be practical for advanced users. (I've been gradually
moving all new scripts over to Ruby because Bash scripts are fragile and not
as inherently reusable as standardizing on a dynamic languages (like RedHat w/
Python).)

------
falcolas
Not to bash <groan> on this, but the real "best" of bash (well, shell
scripting in general) is the simplicity with which you can connect processes
via pipes. Ruby's metaprogramming foo is strong enough that this should be
fairly straightforward to make easy - can we see this please?

~~~
yebyen
One of my favorite Ruby post series of all time:

Pipelines using Fibers in Ruby (1.9)

[http://pragdave.me/blog/2007/12/30/pipelines-using-fibers-
in...](http://pragdave.me/blog/2007/12/30/pipelines-using-fibers-in-ruby-19/)

[http://pragdave.me/blog/2008/01/01/pipelines-using-fibers-
in...](http://pragdave.me/blog/2008/01/01/pipelines-using-fibers-in-
ruby-19part-ii/)

I swear it was actually a 3-part series, but only 2 parts I can find right at
the moment.

~~~
falcolas
Not bad. The syntax is still a bit funky at the end of part 2, but that's a
pretty trivial gripe.

