schwarz

archive of mindset

schwarz header image 5

OpenURI and MemCached sitting in a tree

January 15, 2008 · 2 comments

The ultimate frankenstein-like experiment of harnessing OpenURI and MemCached has been completed!

For a number of projects that used openuri, I needed a way to reduce hits on remote services or rest apis, or even speed up the experience on the client end.

Getting it

sudo gem install openuri_memcached

The beast is alive! (Usage, for those not on late hours right now)

Use exactly the same as you would openuri, only.. enable it.

  require 'openuri_memcached'
  OpenURI::Cache.enable!
  open("http://germanforblack.com").read # Slow as a wet week

Quit your app (leave memcached running) and run the same example, it should now happen in less then … some time that is really fast.

Small print options

To get started run your memcached server

$ memcached -d

The default address that this gem will terminate against is localhost:11211, you can change this using:

OpenURI::Cache.host = ['serverone.com:11211', 'servertwo:11211']

The cache defaults to 15 minutes, however this can be changed using:

OpenURI::Cache.expiry = 60 * 10 # Ten long minutes

Let me know if you have any issues with it, or if you have any use for it!

→ 2 comments Tags:

Introducing GoogleQuery

August 19, 2007 · 0 comments

So, I love Hpricot because it feels like an extension of my hand.

Google (and Yahoo) have awesome human searchable queries like “people in china”.

The top most search result will show you the amount of people in china.

I quickly decided that this would be useless; however incredible to show my mad-ill flow with css selectors.

First, grab the gem from Rubyforge using:

sudo gem install google_query

Leap your ass into irb, require the gem and start screwing around

See how you get spanked by the pound

GoogleQuery::Currency.get 'AUD to GBP'

=> 1 U.S. dollar = 0.490484599 British pounds

Population in Melbourne

GoogleQuery::Population.get 'melbourne'

=> Population: 3,850,000 (Est.) (2nd)

Current time in London

GoogleQuery::Time.get 'london'

=> 2:26 PM on Monday, July 30

On the command line

bens-pb:~ ben$ gpop melbourne

=> Population: 3,850,000 (Est.) (2nd)

bens-pb:~ ben$ gtime london

=> 2:26 PM on Monday, July 30

I couldn’t resist naming it gmoney

bens-pb:~ ben$ gmoney AUD GBP

=> 1 Australian dollar = 0.424269178 British pounds

There you have it, my first gem ever.

Some queries may be broken, this could be due to google changing their search results screen or just no damn results.

→ 0 comments Tags: