Ruby, How Do I Love Thee? Let Me Count the Ways

I just have to say that Ruby is very, very convenient.

Today while working I needed to figure out which ethernet MAC was
missing from a device. So I selected and copied the complete text of
a web page displaying all the MACs on the device. In another window,
using MySQL I selected a list of all the MACs that device SHOULD have
been showing me.

The dilemma–how to eliminate those MACs I could see quickly and
efficiently to leave the missing MACs? Manually comparing the two
lists (one from the device, one from the database) would take far too
long.

Enter Ruby, irb specifically, as a quick-and-dirty text processing
CLI. I pasted my list of MACs from the device into a temporary file,
then did this with irb:

irb(main):001:0> puts “SELECT * FROM authorized_macs WHERE device_id=
2342592 AND mac!=’” +
File.read(‘macs_seen_on_device.txt’).split(/[\r\n]+/).map{|l|
l.split(/\s+/).first}.join("’ AND mac!=’") + “’;”

Thank you, Ruby, for making generating an SQL statement to show me the
missing MACs quick and simple.

Now for a question:

I’ve been looking at Pry to enhance my irb CLI experience and blend a
bit of shell-like CLI in as well. Is there a database module along
the lines of Pry I could use to also integrate a MySQL CLI as well?
I’d love to use Ruby as my system CLI shell and MySQL CLI
simultaneously… drool

Aaron out.

I’d wish Pry was included into standard Ruby - and replace IRB!

-----Messaggio originale-----
Da: Aaron D. Gifford [mailto:[email protected]]
Inviato: mercoled 16 novembre 2011 23:59
A: ruby-talk ML
Oggetto: Ruby, How Do I Love Thee? Let Me Count the Ways…

I just have to say that Ruby is very, very convenient.

Today while working I needed to figure out which ethernet MAC was
missing
from a device. So I selected and copied the complete text of a web page
displaying all the MACs on the device. In another window, using MySQL I
selected a list of all the MACs that device SHOULD have been showing me.

The dilemma–how to eliminate those MACs I could see quickly and
efficiently
to leave the missing MACs? Manually comparing the two lists (one from
the
device, one from the database) would take far too long.

Enter Ruby, irb specifically, as a quick-and-dirty text processing CLI.
I
pasted my list of MACs from the device into a temporary file, then did
this
with irb:

irb(main):001:0> puts “SELECT * FROM authorized_macs WHERE device_id=
2342592 AND mac!='” +
File.read(‘macs_seen_on_device.txt’).split(/[\r\n]+/).map{|l|
l.split(/\s+/).first}.join(“’ AND mac!='”) + “';”

Thank you, Ruby, for making generating an SQL statement to show me the
missing MACs quick and simple.

Now for a question:

I’ve been looking at Pry to enhance my irb CLI experience and blend a
bit of
shell-like CLI in as well. Is there a database module along the lines
of
Pry I could use to also integrate a MySQL CLI as well?
I’d love to use Ruby as my system CLI shell and MySQL CLI
simultaneously…
drool

Aaron out.


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
ING DIRECT Conto Arancio. 4,20% per 12 mesi, zero spese, aprilo in due
minuti!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid924&d)-12

On 11/16/2011 02:58 PM, Aaron D. Gifford wrote:

I’ve been looking at Pry to enhance my irb CLI experience and blend a
bit of shell-like CLI in as well. Is there a database module along
the lines of Pry I could use to also integrate a MySQL CLI as well?
I’d love to use Ruby as my system CLI shell and MySQL CLI
simultaneously… drool

Check out sequel[1] – nice CLI as well as API:

$ sequel sqlite:/
Your database is stored in DB…

DB
=> #<Sequel::SQLite::Database: “sqlite:/”>
mac_array = [1,2,3]
=> [1, 2, 3]
DB[:authorized_macs].filter(:device_id => 123).exclude(:mac =>
mac_array)
=> #<Sequel::SQLite::Dataset: “SELECT * FROM authorized_macs WHERE
((device_id = 123) AND (mac NOT IN (1, 2, 3)))”>

(works with other dbs besides sqlite, of course; and you can get all
this functionality in irb just by requiring sequel)

[1] http://sequel.rubyforge.org/

-----Messaggio originale-----
Da: Joel VanderWerf [mailto:[email protected]]
Inviato: gioved 17 novembre 2011 00:32
A: ruby-talk ML
Oggetto: Re: Ruby, How Do I Love Thee? Let Me Count the Ways…

On 11/16/2011 02:58 PM, Aaron D. Gifford wrote:

I’ve been looking at Pry to enhance my irb CLI experience and blend a
bit of shell-like CLI in as well. Is there a database module along
the lines of Pry I could use to also integrate a MySQL CLI as well?
I’d love to use Ruby as my system CLI shell and MySQL CLI
simultaneously… drool

Check out sequel[1] – nice CLI as well as API:

$ sequel sqlite:/
Your database is stored in DB…

DB
=> #<Sequel::SQLite::Database: “sqlite:/”> >> mac_array = [1,2,3] =>
[1, 2,
3] >> DB[:authorized_macs].filter(:device_id => 123).exclude(:mac =>
mac_array)
=> #<Sequel::SQLite::Dataset: “SELECT * FROM authorized_macs WHERE
((device_id = 123) AND (mac NOT IN (1, 2, 3)))”>

(works with other dbs besides sqlite, of course; and you can get all
this
functionality in irb just by requiring sequel)

[1] http://sequel.rubyforge.org/


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Conto Arancio al 4,20%. Soldi sempre disponibili, zero spese, aprilo in
due minuti!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid920&d)-12