You win some, you loose some
June 24, 2008 01:44 (about 2 years ago)
| 0 comments
Stuff happening here. Two of my old friends are getting married; one, an old buddy with whom I grew up but have lately lost contact to a bit and the other a girl who I used to know quite well. Its like being in warp speed at the moment, years seem to fly by. Things are getting more serious, pressure and responsibility increases, but you just can’t shake the feeling that you still are the same. Anyhow… I spend some quality time with the old crew running a gig in the Netherlands . Good stuff. We played serious poker, smoked Cuban cigars and drowned our losses in straight single malt. You can only exchange stories from the past for so long, listen to your once favorite songs a couple of times, before the present is there. Well, its not the same as it used to be, but good none the less. The mundanites followed on heal the minute I was back. I ran upgrades on the server and killed my rails app. The transition from 1.2. to 2.1 saw the a…
read more

If you read scientific articles every now and again, you probably know what it is like to stumble upon an exceptionally well written one. Well, rare as it is it does happen. When reading Nature articles that are outside of my scope, I rarely read beyond the abstract. If I do, I rapidly get lost in the myriads of details and the use of strange, detached scientific sounding English. A recent article in Nature entitled
Quantifying the evolutionary dynamics of Language by Liebermann
et al (
Nature 449, 713–716; 2007) marks the exception. The theme of the paper is simple but intriguing: the decay of irregular verbs in the English language and how verb regularization is dependent on the frequency of use. In the study, the authors have create…
read more
Random entries
March 24, 2008 14:21 (over 2 years ago)
| 0 comments
A recent challange I encoutered was getting random entries from a model. In particular, I wanted to get x number of random Links from my link database. Essentially, I wanted to by able to say
Link.random(2)
and then get back random Link objects. I messed around with a couple of things, and ended up doing the following in my Link model
class Link < ActiveRecord::Base
def self.random(number)
links = Array.new
seen = Hash.new(0)
randid = 1
count = 0
number.downto(1) { |n|
loop do
randid = rand(Link.count)+1
begin
self.find(randid)
rescue
seen[randid] += 1
end
break unless seen.has_key?(randid)
end
seen[randid] += 1
puts seen.to_s
links << Link.find(randid)
}
return links
end
end
The only p…read more