Overrides in Camping

If you want to add a call to all the controllers in your Camping miroframework app you can use before or after overrides. These are similar to the before_filter in Rails.

Remember to return the superclass or Camping will throw a “Read error: #<NoMethodError: undefined method `status’ for nil:NilClass>” because it can’t call back into the returned controller. A modification of the above linked wiki page example illustrates -


Camping.goes :YourApp

module YourSession
  def service(*a)
    @session = YourApp::Session.new
    s = super(*a)
    @session.close
    #return s from above after completing
    s
  end
end

module YourApp
  include YourSession
end

camping
dev
ruby

Comments (0)

Permalink

How much does nuclear power really cost?

Forbes had an article on the true cost of nuclear power in the US. It turns out clean coal generated power is only slightly more expensive than regular coal. On the other hand Nuclear power is significantly more expensive and only makes economic sense because of subsidies.

I didn’t see a chart in the the article so I made one with their statistics. Enjoy.

Comparative cost of different power generating methods

viz

Comments (6)

Permalink

Branding Mupatu

A sarcastic, dark but hilarious view of the advertising industry. Check it out…It might take a little while to start…

satire
video

Comments (0)

Permalink

Funny Cigarette Disposal Sign


DSC04825

Originally uploaded by c h i c k e n ^V^.

A funny cigarette disposal sign I saw on flickr. Even though it is worded badly, it makes some good points.

engrish
photography

Comments (0)

Permalink

Optimizing an SQL LIKE Query

Carlos did a quick test earlier in the day on our Apache Derby backend and found that in a particular like query Derby was 23x slower than on a equality query over the same data set. Very often, databases do not optimize LIKE queries, partially because it is rare for them to support the types of indices such optimizations would require.

It took me a little while to find this gem on LIKE Transformations in the Derby tuning manual. Basically the document covers some transformations which the Derby SQL parser goes through to make LIKE queries optimizable. For me, this solved the problem as it allowed me to rewrite my query into a form that was optimizable albeit with a slight loss of functionality in my application. Unfortunately, this is not the case for all LIKE queries. The transformations are quite obvious and easy to follow once you see them, so take a look if you are having similar performance problems.

Before:

SELECT checksum FROM tags WHERE tag LIKE ‘%element%’

Gets parsed into – SELECT checksum FROM tags WHERE tag LIKE ‘%element%’

After

SELECT checksum FROM tags WHERE tag LIKE ‘element%’

Gets parsed into – SELECT checksum FROM tags WHERE tag >= ‘element’ AND tag < 'elemenu'

These transformations are also potentially useful with databases other than Derby when LIKE queries are running slow, as you could do them manually on your statements to the fullest extent possible potentially eliminating LIKE altogether.

SQL
db
dev

Comments (0)

Permalink