Courtesy of Twitter

Archive for the ‘Uncategorized’ Category

This is genius!

Friday, October 24th, 2008

I read Mike Gunderloy’s blog post today and afterwards thought he was crazy! I thought you couldn’t do Blog.find(”1-title”).

But you can.

If you pass in 1-title as params[:id] for any action and then pass it to find, find will do its “thing” and just execute find(1), giving you pretty URLs AND pretty code.

I later found out this was because find just calls to_i when it gets given strings, and calling it on “1-title” will give you “1″.

Ruby Quiz - Matricies

Wednesday, October 22nd, 2008
nb = 5
distance = Array.new(nb, Array.new(nb))
k = 0
(0...nb).each do |i|
  (0...nb).each do |j|
    distance[j][i] = k +=1
  end
end
 
puts distance.inspect

This code should generate:
[[1,6,11,16,21], [2,7,12,17,22], [3,8,13,18,23], [4,9,13,19,25], [5,10,15,20,25]]

But generates:
[[5,10,15,20,25], [5,10,15,20,25], [5,10,15,20,25], [5,10,15,20,25], [5,10,15,20,25]]

I learned why today, and I wonder if anyone else knows.

Did you (Rails) Rumble?

Monday, October 20th, 2008

NO

I spent the weekend learning (read: having an affair with) Merb. I’m porting rboard to mboard whenever I feel like doing some merb. This is in the interest of seeing how much merb actually kicks Rails’ ass and a learning experience for me.

Also, Merb’s source code is very, very pretty.

Throat Cramps

Thursday, October 16th, 2008

Occasionally when I’m moving my head I get these throat cramps just on the right side of my throat. During these cramping phases the muscle (?) that moves up and down when you swallow (have a look in the mirror and watch your throat as you swallow, you’ll know what I mean) is what cramps. This can be extremely painful and I know of nobody else who gets these. I can only describe it as a cramp. There is a large sharp pain (kind of like when you get hit in the throat) when swallowing and a slightly lesser pain when I tilt my head backwards or to the left. Again, this only happens on one side of my throat.

I was prescribed anti-histamine tablets last year for this problem and it’s only manifested itself 4 times since then, the last 2 times have been within a month of each other. Generally, tilting my head back and drinking about a litre of water helps, but not the last two times. The last two times I’ve had to wait it out, and it’s been 3 hours and 1 hour respectively.

Has anybody out there in the blogosphere heard of this before?

Two Guys Break Into A Car…

Thursday, October 9th, 2008

Well, I’ll assume it was two. Some idiot(s) in the middle of the night smashed the corner of my back-right window and rifled through my car looking for something. Obviously they didn’t find it because the car is still there. They changed the gearstick to reverse, took off the handbrake and moved an American flag I had in the boot into the backseat (I know! The outrage!). Everything’s still in the car, just in more disarray than usual.

Orderly Code is Readable Code

Tuesday, October 7th, 2008

We were talking in #offrails today about coding standards and a few points came up on how to lay out “good” rails code. They were:

  • Controllers laid out in this order: index, show, new, create, edit, update, destroy, custom actions
  • Models laid out in this order:  Associations, Validations, Callbacks, Class Methods, Instance Methods
For controllers I would put filters first, then the 7 restful actions (index, show, new, create, edit, update and destroy) and then the custom actions and then if I needed to find a parent resource (for example /forums/1/topics) I would call private and then put a find_forum method there.

The Super-Consumer

Tuesday, September 30th, 2008

So I have this friend who’s the same age as me. He doesn’t work. He doesn’t appear to be actively looking for work. He got “fired” from his last job because he wasn’t fast enough, but apparently the boss was an asshole. There was an excuse for the job before it too, but I can’t remember what that was. He’s constantly getting new things. I’d like to refer to him as a “super-consumer”, someone who has too much. He loves NERF and Transformers (keeping in mind he’s the same age as me). He’s never outwardly happy with the things he has, and is constantly in a “covet thy neighbour” state of mind (and he’s Christian!), always wanting the next level up as soon as it’s been released. Take for instance the graphics card I won at AsLAN in a silent auction. He asked me if I could put my brand new graphics card into his media center. His argument was for when he has movie nights, then I will appreciate the gift I gave unto him. Admittedly, it’s a card I have no use for, at the moment, but it’s always handy to have a spare in case things go wrong. So, rather than him actually putting the energy used into his craving for all that is new & shiny into finding work so that he can buy all that is new & shiny, he just craves. I think this path is going to destroy him, and there’s nothing I can do or say that will open his eyes to what he is bringing on himself.

A List of Police-related Shows on Australian Free-to-air TV

Monday, September 29th, 2008

The Bill
Taggart
CSI: Miami
Crime Investigation Australia
CSI: NY
Dexter
Bones
City Homicide
The Force - Behind the line
Border Security - Australia’s Front Line
NCIS
Criminal Minds
Life
Law & Order: Criminal Intent
Law & Order: SVU
Motorway Patrol
Police Ten 7
Miami Vice
The Strip
Inspector Rex

How To Ask For Help

Thursday, September 25th, 2008
  1. Have you tried stopping your server and starting it? This fixes many problems and may fix yours!
  2. If you’re getting a NoMethodError which ends in “The error occured when evaluating nil.method” this means you’re trying to call a method on a nil object! Check the object that you’re calling that method on and make sure that it actually is set!
  3. Google the error message. If you’re getting “undefined method `blah`”, try googling just “undefined method”. Never ask a question without googling first.
  4. State your problem clearly. Never, ever say “I have a problem plzzzz help me !!!1!” or ” is not working” or something to that effect. Say, for example, that you’re getting an undefined method. Type “pastie: hi” into the channel and the pastie bot will send you a link via private message where you can show us your code, stack trace and error. Giving all three will provide us 99% of the time with the information we need to help you solve your problem.
  5. Don’t use dummy examples. An example would be asking a question like “How does A relate to B?” when asking “How does a blog relate to comment?”.
  6. Don’t ask “can you do <thing> with Rails?”, because the most often answer is “Yes”. Ask rather “How can you do <thing> with Rails?”
  7. Don’t ask to ask, just ask.
  8. Paste anything over 3 lines of code using the pastie service (type “pastie: hello”) into the channel and the pastie bot will send you a link via private message where you can put your code.
  9. Don’t ask “Has anybody used <thing>?” rather state your problem that you’re having with <thing> and somebody may be able to help you. See #2.
  10. Don’t prefix your question with a statement or another question. For example just write your problem rather than prefixing it with something like “Can anyone help me with this? <problem>” or “I am a noob help me with <problem>” or “I have a problem… <problem>” it’s a waste of your time typing it out and a waste of our time reading it.
  11. Computers never lie.
  12. Don’t ask subjective questions. “Subjective” means a question that’s answer is entirely opinion based, such as questions like “What is the best text editor?” or “What is the best testing framework?”

And Now For Something Completely Useless

Tuesday, September 23rd, 2008
class Model < ActiveRecord::Base
  has_many (Dir.entries("#{RAILS_ROOT}/app/models")-['.','..',"#{self.to_s.downcase}.rb"]).delete_if{|a|
File.directory?("#{RAILS_ROOT/app/models/#{a}")}.rand.gsub(".rb","").pluralize.to_sym
end