orca_card 1.0
Eric Hodel | Tue, 19 May 2009 18:54:33 GMT
orca_card version 1.0 has been released!
Dumps information about your ORCA card. ORCA cards are Western Washington’s all-in-one transit smart card that allow travel via bus, train and ferry throughout King, Kitsap, Snohomish and Pierce counties.
NOTE: This is a cheap hack, patches wanted
imap_processor 1.1
Eric Hodel | Mon, 18 May 2009 22:56:00 GMT
imap_processor version 1.1 has been released!
IMAPProcessor is a client for processing messages on an IMAP server. It provides some basic mechanisms for connecting to an IMAP server, determining capabilities and handling messages.
IMAPProcessor ships with the imap_keywords executable which can query an IMAP server for keywords set on messages in mailboxes.
Changes:
- 1 minor enhancement
- IMAPProcessor#each_message allows messages to be omitted from the returned uid list (skipped)
imap_to_rss 1.0
Eric Hodel | Fri, 15 May 2009 18:17:00 GMT
imap_to_rss version 1.0 has been released!
IMAPToRSS turns messages on an IMAP server into RSS entries when the match a handler. Included handlers work for email from Amazon, HSBC and UPS. IMAPToRSS automatically loads handlers for any other mail.
I wrote an inliner
Eric Hodel | Wed, 27 Jun 2007 07:35:00 GMT
$ ruby test.rb
caller result: 12
caller:
def caller
v1 = (2 + 3)
x = callee(v1)
(x + 2)
end
callee:
def callee(v)
(v + 5)
end
inline callee into caller
caller result: 12
caller:
def caller
v1 = (2 + 3)
x = (inline_callee_v = v1
(inline_callee_v + 5))
(x + 2)
end
$ ruby -Ilib bm.rb
Rehearsal -------------------------------------------
empty 0.090000 0.000000 0.090000 ( 0.083842)
plain 1.030000 0.010000 1.040000 ( 1.037302)
inlined 0.810000 0.000000 0.810000 ( 0.821394)
---------------------------------- total: 1.940000sec
user system total real
empty 0.080000 0.000000 0.080000 ( 0.084179)
plain 1.100000 0.000000 1.100000 ( 1.105742)
inlined 0.900000 0.000000 0.900000 ( 0.900799)
render_tree for Rails
Eric Hodel | Fri, 08 Sep 2006 18:02:00 GMT
Spelunking deep in unfamiliar Rails view code? Flushing out the cobwebs and updating your code? Don't know what gets rendered when?
I have a solution for you:
class ActionView::Base
alias plain_render render
RENDERS = [:partial, :template, :file, :action, :text, :inline, :nothing,
:update]
def render(*args)
@level ||= 0
print ' ' * @level
case args.first
when String then
p args.first
when Hash then
hash = args.first
found = hash.keys & RENDERS
if found.length == 1 then
puts "%p => %p" % [found.first, hash[found.first]]
else
raise "Dunno: %p" % [hash]
end
else
raise "Dunno: %p" % [args]
end
@level += 1
result = plain_render(*args)
@level -= 1
result
end
end
Drop that in test/render_tree.rb and require it in your tests when you want to see a tree like this:
$ ruby test/views/things_view_test.rb -n test_view
Loaded suite test/views/things_view_test
Started
"things/things-header"
"things/sidebar"
"widgets/forms/goal_form"
:partial => "widgets/sidenav_boxes/invite_and_edit"
"widgets/sidenav_boxes/_invite_and_edit"
:partial => "widgets/forms/edit_worth_doing_form"
"widgets/forms/_edit_worth_doing_form"
:partial => "widgets/sidenav_boxes/tags"
"widgets/sidenav_boxes/_tags"
:partial => "widgets/sidenav_boxes/popular_places"
"widgets/sidenav_boxes/_popular_places"
:partial => "widgets/sidenav_boxes/google_ads"
"widgets/sidenav_boxes/_google_ads"
:partial => "widgets/sidenav_boxes/find_help"
"widgets/sidenav_boxes/_find_help"
:partial => "widgets/sidenav_boxes/people_who_reached_this_goal"
"widgets/sidenav_boxes/_people_who_reached_this_goal"
:partial => "widgets/sidenav_boxes/quotation"
"widgets/sidenav_boxes/_quotation"
:partial => "widgets/sidenav_boxes/goal_created_by"
"widgets/sidenav_boxes/_goal_created_by"
"widgets/general/post_add_messages"
"things/shared_body"
:partial => "widgets/goals_gallery_teaser"
"widgets/_goals_gallery_teaser"
:partial => "entries_bucket"
"things/_entries_bucket"
"widgets/forms/related_goals"
.
Finished in 1.205494 seconds.
1 tests, 7 assertions, 0 failures, 0 errors
(I think I'll end up throwing this into ZenTest.)
Markov Chain
Eric Hodel | Sun, 26 Feb 2006 00:39:00 GMT
The back of my brain has been wanting a Markov chain based random-text generator for some time. I found some decently explanatory pseudo-code in the Generating Text section of the online Programming Pearls by Jon Bently.
What I really wanted was something that illustrated the concept well so I could tell what it was doing. The perl, python and ruby versions I found weren’t simple enough for me to see that. I also wanted to adjust the amount of state in the chain, but the only implementations that supported that were far too complicated to figure out.
Working from Jon Bently’s pseudo-code I ended up with the following implementation. Read more...
httpdump
Eric Hodel | Mon, 23 Jan 2006 07:34:00 GMT
I wrote a nifty little combination of a WEBrick servlet and a ruby-pcap http grabbing example that lets you see the latest HTTP requests that have crossed a network card interface.
All so I can spy on my neighbors (but they can also spy on me).

Articles