{ |one, step, back| } 2 of 2 articles Syndicate: full/short

Innovative Identification   28 Sep 05
[ print link all ]

Dick Hardt’s OSCON 2005 keynote talked about how to identify yourself online. Here’s an IRC conversation the ensued after I accidently issued a sudo command on a friend’s system, one that is monitored very closely by the sysadmin.

[22:35] <paulv>    matthew immediately declared that we were already cracked. :)
[22:35] <matthew>  yeah, it's all good.  Although, can you prove you're Jim?
[22:35] <jweirich> yes
[22:35] <jweirich> ask me a Ruby question
[22:35] <paulv>    implement the Y-combinator!
[22:35] <matthew>  heh
[22:35] <paulv>    then I'll believe.
[22:36] <jweirich> p proc { |le|
[22:36] <jweirich>   proc { |f| f.call(f) } \
[22:36] <jweirich>   .call ( proc { |f|
[22:36] <jweirich>            le.call (proc { |x| f.call(f).call(x) }) })
[22:36] <jweirich> }.call(proc { |recurse|
[22:36] <jweirich>   proc { |n|
[22:36] <jweirich>     if n == 0 then
[22:36] <jweirich>       1
[22:36] <jweirich>     else
[22:36] <jweirich>       n * recurse.call (n-1)
[22:36] <jweirich>     end
[22:36] <jweirich>   }
[22:36] <jweirich> }).call(5)  
[22:37] <matthew>  wow.  This is better than gpg keys.
[22:37] <matthew>  I hope you had that laying around 
[22:37] <jweirich> nah, did it from memory ;)
[22:37] <paulv>    this *is* better than GPG keys.

(and for those that missed the winking smiley, no, I did not do this from memory)

Update

I see that Dick Hardt’s OSCON 2005 presentation on Identity 2.0 is available at http://www.identity20.com/media/OSCON2005. This is worth seeing.


comments

Today's One Liner   18 Sep 05
[ print link all ]

I don’t usually talk must about one-liners, but here’s one I used today.

ARGF and inject ... Two Great Tastes that Taste Great Together

Consider the following ruby one-lineer

ruby -e 'p ARGF.inject(0) { |sum, line| line.split[1].to_i + sum }'

Breaking it down, it …

  • Iterates over each line of standard input (ARGF.inject(0))
  • Splits the line into colums (line.split)
  • Selects the second column ([1])
  • Converts the second column to an integer (.to_i)
  • Adds to to the running subtotal (+ sum)
  • And prints the final sum (p)

In short, it sums up the numbers in the second column of a text file.

Cool. Now combine it with another one-liner …

lynx -dump http://gems.rubyforge.org/stats.html \
  | ruby -e 'p ARGF.inject(0) { |s,t| t.split[1].to_i + s }'

And you get the result …

1005821

... which is the number of gems served by RubyForge to date.

Over 1 million gems served :)


comments

 

Formatted: 10-Oct-08 22:43
Feedback: jim@weirichhouse.org