So I was reading through the Haskell Prelude when I stumbled across `scanl’ as a kind of abstraction over `foldl’. I stared, and thought, and stared some more, and couldn’t come up with a use for it; a quick Web search revealed exactly one use: Fibonacci numbers.
(In retrospect: duh.)
So here are all the Fibonacci numbers [...]
Author Archives: Mike Burns
An Infinite List of Fibonacci Numbers in Ruby
Powerset in Ruby Using the List Monad
While trying to think of good, quick interview questions I stumbled across power set (thanks to Mike DiStaula for suggesting it). After 10 minutes of hacking in Ruby I discovered that it’s not a reasonable replacement for our current starter question (it takes too long), but it’s also a fun problem to solve.
Then I wandered [...]
Correctly Handle OpenID Updates
OpenID is pretty well established as a login infrastructure, but a topic often ignored is correctly letting the user change his saved OpenID. Don’t just save the text they enter! Verify that they’ve entered their valid OpenID.
The user model needs to pass this test:
should_have_db_column :new_openid_identity, :type => ’string’
The view on /account/edit needs to pass this [...]
Save Those Receipts!
Over the weekend I was on a team of (potential) winners participating in the 2008 Rails Rumble. The application idea was something that I had prototyped for myself years ago and quickly lost, and it solves the problem I had at the time:
I was living near Fenway, and I suffered from too many choices of [...]
Uniquify an array of hashes in Ruby
Array#uniq is a handy Ruby method that produces an array of distinct elements. So, for example, [1,2,3,3,3].uniq produces [1,2,3].
However, this fails on an array of hashes. For example, [{}, {}].uniq actually produces [{},{}]. That’s not what I wanted, recently.
It turns out that #uniq uses the methods #hash and #eql? to determine uniqueness, and Hash#hash produces [...]
Spider bugfix
There were two issues with version 0.4.0 of Spider, both caught by Henri Cook. These are now fixed in 0.4.1:
As documented, you use IncludedInMemcached like this: require ’spider/included_in_memcached’ .
Sometimes HTTP redirects assume a base URL; this is now handled.
Spider with memcached
The problem with Spider has been that it can use all your memory. The reason is that the Web is a graph, and to avoid cycles Spider stores each URL it encounters. Since the Web is a really, really, really gigantic graph, you eventually run out of memory.
Now you can use memcached to use not [...]
Proxied Spider
Aha: if you need to proxy your Spider calls, look no further than the HTTP Configuration gem.
I didn’t write this, and have yet to use it, but I think it goes like this:
http_conf = Net::HTTP::Configuration.new(:proxy_host => ‘localhost’, :proxy_port => 8881)
http_conf.apply do
Spider.start_at(‘http://example.com/’)
end
So next up will be a tutorial with stuff like this and other [...]
Spider: API changes, setup and teardown, HTTP headers
The newest version of Spider, 0.3.0, is hitting your gem tree Real Soon Now. This release features:
Set the headers to a HTTP request.
This can be used to set the cookies, user agent, and many other fine things.
setup and teardown handlers.
Seems like a good place to set the headers if the headers are conditional on the [...]
Spider bug fix release
John Nagro immediately reported errors with the Spider Ruby gem, so I’ve fixed them in 0.2.1. You should upgrade, especially if you want support for:
URLs without any path component (e.g. http://example.com?s=1).
HTTP redirects.
HTTPS.
John also had some good ideas, so here is what is in the works:
The ability to construct a complete graph of every node found.
Defeat [...]