Courtesy of Twitter

Archive for the ‘Cool Shit’ Category

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:

 remove_column :table, :column_1
 
remove_column :table, :column_2
 
remove_column :table, :column_3
 
remove_column :table, :column_4...

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 remove_columns was add_columns (already spied by the observant few). There’s a little difference in add_columns compared with add_column, the type is now the second argument instead of the third:

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

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:

 remove_column :table, :column_1
 
remove_column :table, :column_2
 
remove_column :table, :column_3
 
remove_column :table, :column_4...

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 remove_columns was add_columns (already spied by the observant few). There’s a little difference in add_columns compared with add_column, the type is now the second argument instead of the third:

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