Archive for the ‘Cool Shit’ Category

distance_of_time_in_words

Friday, August 7th, 2009

I was infatuated with this method when I first saw Rails but I’ve seen a couple of people recently express that Rails’ built in distanceoftimeinwords is not accurate enough, showing something like “about 2 years” rather than “2 years, 21 days, 5 hours, and 6 minutes”. With some help from chendo at Mocra (where I work) I’ve made a new distanceoftimeinwords which should be a drop-in replacement for the old crappy one. To install it, use: script/plugin install git://github.com/radar/dotiw.git. This also comes with another method if you’re still picky about the output: distanceoftimeinwords_hash which gives you a Hash containing keys in your native tongue. The README should give you a good guide of what other options it supports too.

humanize

Saturday, July 4th, 2009

I was inspired earlier in the year by Brenton Fletcher’s humanize that I decided to make my own. Today, I “finished” it with the help of Mitchell Riley and other Actionhackers. Humanize will convert numbers up to a very large number of digits long into their string versions. This means given the number:

444,333,222,111,999,777,666,555,444,333,222,111,999,777,666,555,444,333,221,111,112,176,514,321,007,310, 444,333,222,111,999,777,666,555,444,333,222,111,999,777,666,555,444,333,221,111,112,176,514,321,007,310

Yes it’s the same sequence repeated twice, I got lazy in my testing. imagine it conjoined into one very large number.

Coincidentally, this is my IQ.

I get:

four hundred and forty four quinquagintillion, three hundred and thirty three novenquadragintillion, two hundred and twenty two octoquadragintillion, one hundred and eleven septenquadragintillion, nine hundred and ninety nine sesquadragintillion, seven hundred and seventy seven quinquadragintillion, six hundred and sixty six quattuorquadragintillion, five hundred and fifty five trequadragintillion, four hundred and forty four duoquadragintillion, three hundred and thirty three unquadragintillion, two hundred and twenty two quadragintillion, one hundred and eleven novemtrigintillion, nine hundred and ninety nine octotrigintillion, seven hundred and seventy seven septentrigintillion, six hundred and sixty six sextrigintillion, five hundred and fifty five quintrigintillion, four hundred and forty four quattuortrigintillion, three hundred and thirty three trestrigintillion, two hundred and twenty one duotrigintillion, one hundred and eleven untrigintillion, one hundred and twelve trigintillion, one hundred and seventy six novemvigintillion, five hundred and fourteen octovigintillion, three hundred and twenty one septenvigintillion, seven sexvigintillion, three hundred and ten quinvigintillion, four hundred and forty four quattuortillion, three hundred and thirty three trevigintillion, two hundred and twenty two duovigintillion, one hundred and eleven unvigintillion, nine hundred and ninety nine vigintillion, seven hundred and seventy seven novemdecillion, six hundred and sixty six octodecillion, five hundred and fifty five septendecillion, four hundred and forty four sexdecillion, three hundred and thirty three quindecillion, two hundred and twenty two quattuordecillion, one hundred and eleven tredecillion, nine hundred and ninety nine duodecillion, seven hundred and seventy seven undecillion, six hundred and sixty six decillion, five hundred and fifty five nonillion, four hundred and forty four octillion, three hundred and thirty three septillion, two hundred and twenty one sextillion, one hundred and eleven quintrillion, one hundred and twelve quadrillion, one hundred and seventy six trillion, five hundred and fourteen billion, three hundred and twenty one million, seven thousand three hundred and ten.

Props to this site which gives names to unimaginably large numbers.

I have yet to find a use for this, but I’m sure somebody out there can.

NOW WITH FASTER PEFORMANCE! Thanks to Jack Chen.

no such file to load — hmac-sha1

Friday, July 3rd, 2009

When you encounter the above error, it means you’re missing the ruby-openid ruby-hmac gem. I couldn’t find anything on google that clearly stated this, so I’m posting it here as a reminder for myself and others.

Thanks to the comments for clarifying the gem needed.

21st Birthday

Monday, November 24th, 2008

I’m going to be having a party at the Tap Inn starting @ 6:30pm @ The Tap Inn on the 4th December. Those wishing to come please contact me using the usual means.

Beware!

Monday, February 4th, 2008

Today I visited a place I have only visited around three times. It’s plain and boring and generally you only ever go there to lose a lot of money very quickly so you can move around faster (legally) than if you never gave that money away. I made a terrible, terrible mistake by going in at lunchtime. The line was half way to the back of the place and by the time I reached the front the line extended out of it, and then more. I filled out a form with my details on it.

I sat down and read a book, a 70-something page book, whilst little children squealed and bashed trolleys against the bench. I watched as a grown man was pleading with the police to “stop breaking my arms dudes!” as he was escorted out. I finished the book, extremely bored with what I just read and let’s just say it wasn’t a Lord of the Rings or Curse of the Chosen.

I lined up again in the almost-impossibly long line that was moving even more impossibly slower, thankful that it wasn’t my child that was making all that racquet. If only there were noise laws against children and people talking on mobile phones obnoxiously loud. The line shuffled forward, ever slowly. I reached the front and was told to fill out yet another form with my details on it (maybe they just really need to make sure it was me?) and to walk over to the other counter with a piece of paper.

I waited whilst a man of asian appearance argued with one of the staff about the identity of his wife (she had a different last name on her passport) and thankfully another staffer came over and assisted me. He told me to sit down at a desk, walked around a corner and asked if I could see anything. I said I couldn’t,  and he disappeared for a few more seconds. Something came up on the screen and he asked if I could see anything, and I politely (but nervously) replied that I could.

I touched the screen and followed the instructions, I focussed eagerly, and at times I suspect on the wrong things and pressed the screen when I was told to. After a few minutes of doing this and listening to the asian man still get more frustrated about the identity of his wife, I completed it.

I was congratulated, and asked to fill yet another form about my identity (maybe they just really really needed to make sure it was me) and walked out of there with a smile on my face and two pieces of paper in my hand.

I did my Hazard Perception Test. I passed first go. I beat my brother to it. That’s all that matters. One step closer to a full license.

If you do it, pay more attention to the indicators.

More Migration Sexiness – remove_columns & add_columns

Wednesday, December 19th, 2007

After seeing a post on errtheblog about them making migrations sexier, I was inspired on the train ride this morning to write something similar. I had a table and I wanted to drop many columns for it and I ended up writing something like:

 removecolumn :table, :column1

removecolumn :table, :column2

removecolumn :table, :column3

removecolumn :table, :column4...

and by now you’re starting to get the idea. I have to not only type out remove_column four times, but also the table name! What a waste of time!

So I hacked up some code and put it into lib/custommethods.rb.

module ActiveRecord
  module ConnectionAdapters
    class MysqlAdapter
      def removecolumns(tablename, *columns)
        columns.each { |column| removecolumn table_name, column }
      end

  def add_columns(table_name, type, *columns)
    columns.each { |column| add_column table_name, column, type}
  end
end

end end

So now instead of the monstrosity above I can now type:
removecolumns :table, :column1, :column2, :column3, :column_4
to remove all the columns.

Also inspired by removecolumns was addcolumns (already spied by the observant few). There’s a little difference in addcolumns compared with addcolumn, the type is now the second argument instead of the third:

addcolumns :table, :string, :column1, :column2, :column3

More Migration Sexiness – remove_columns & add_columns

Wednesday, December 19th, 2007

After seeing a post on errtheblog about them making migrations sexier, I was inspired on the train ride this morning to write something similar. I had a table and I wanted to drop many columns for it and I ended up writing something like:

 removecolumn :table, :column1

removecolumn :table, :column2

removecolumn :table, :column3

removecolumn :table, :column4...

and by now you’re starting to get the idea. I have to not only type out remove_column four times, but also the table name! What a waste of time!

So I hacked up some code and put it into lib/custom_methods.rb.

 module ActiveRecord
module ConnectionAdapters
class MysqlAdapter
def remove_columns(table_name, *columns)
columns.each { |column| remove_column table_name, column }
end
def add_columns(table_name, type, *columns)
columns.each { |column| add_column table_name, column, type}
end
end
end
end

So now instead of the monstrosity above I can now type:

remove_columns :table, :column_1, :column_2, :column_3, :column_4

to remove all the columns.

Also inspired by removecolumns was addcolumns (already spied by the observant few). There’s a little difference in addcolumns compared with addcolumn, the type is now the second argument instead of the third:

add_columns :table, :string, :column_1, :column_2, :column_3