Courtesy of Twitter

Archive for September, 2007

Pity the Fool

Saturday, September 22nd, 2007

I feel sorry for the people who code in Java and you should too. Their “hello world” program is 5 lines long, 5 times longer than Ruby’s. Not only do you have to write out five lines, but then you have to compile and then execute it.

(all Java examples stolen from the [url=http://en.wikipedia.org/wiki/Java_%28programming_language%29]Java (programming language) page[/url]

[code=”Java: Hello World”]
public class Hello {
public static void main(String[] args) {
System.out.println(”Hello, World!”);
}
}
[/code]

Ruby’s Hello World on one line:

[code=”Ruby: Hello World (irb)”]
puts “hello world”
[/code]

And then how about this example in order to tell if a number is odd or even:

[code=”Java: Odd Or Even”]
public class OddEven {
private int input;

public OddEven() {
input = Integer.parseInt(JOptionPane.showInputDialog(”Please Enter A Number”));
}

public void calculate() {
if (input % 2 == 0)
System.out.println(”Even”);
else
System.out.println(”Odd”);
}

public static void main(String[] args) {
OddEven number = new OddEven();
number.calculate();
}
}
[/code]

And Rails’:

[code=”Rails: Odd or Even (script/console)”]
>> 2.even?
=> true
[/code]

Rocky

Wednesday, September 19th, 2007

There’s this lady who works in the accounts department at SeaLink and they call her Rocky. She got that nickname for apparently coming into work with a broken neck. On Sunday night her mum suddenly passed away and she took the week off work to grieve. The funeral is today.

And then [url=http://www.news.com.au/adelaidenow/story/0,22606,22448973-2682,00.html]this happened last night[/url]. Rocky’s son was killed in a car rollover last night when he was only 17. I can’t imagine her emotional state right now, after losing her mother so quickly and then her son.

Act Like A Pirate Day

Tuesday, September 18th, 2007

I wrote me a “speech” for today’s Scrum (a short meeting which the crew state what they done yesserday and what they are going to do today) for meself and my second mate.

Me speech be:
Ahoy landlubbers! Yesserday me and my crew wrought the mother ‘o’ all tests, Aye, she was a beauty to behold. The controller tests were ‘ardly a worthy adversary and I slayed them with me keyboard! Yarrr!

When the sun was high, Firs’ Maaate Adam reported some of the lubberly model tests were planning a mutiny! They fought well but by sundown their numbers were just two Arr! The cowardly dogs retreated but we anticipate they be back today! A fight to behold it will be! Afterwards me and my crew will gather a motherload of grog and booty and sail off into the sunset!

Yarrrr!

Me second mate’s speech be:

Ahoy! Arr! Las’ nigh me and my crew were attacked by the scurvy seadog Vehicle Price Breaks and his seawench Logic! Thi’ here scribble shows the seawench is both a sight to behold and a fearsome foe! Yar…

Me and First Mate Ryan will show ye Skipper our loot and he shall gaze upon it with amazement! The skipper will ask intricate questions to which we shall reply in complex convoluted answers. Skipper will stroke his beard muterring “Yar…” in approval. After a hard day’s work, I gather me some grog and sail back to me loves.

I Hate Banks

Saturday, September 15th, 2007

You’ve recently selected to buy something from eBay and to do so you need to transfer money from your account to a Hong Kong bank account. Thankfully, you think, there’s this little thing called the Internet which has Internet Banking on it so you decide you would go to use that.

After about 20 minutes of frustration by realising the person who was selling you the item did not give you a BSB number, You decide to call the bank’s number. First you get a “For account enquries please press 1″ and so on. This is not welcoming. Eventually the LAST option (option #5), general enquiries, is the one you want. You press that and instantly you’re transported into a world of pain listening to the relaxing “music” they play when you’re on hold and the stupid voice overs that tell you about all the “great” things about the bank.

Eventually you’re put on to a real person. You tell them what you want to do and they nearly trip over themselves trying to help you. They go through a list of about 9 things you need. You have the first 8. The 9th is an IBAN or International Bank Account Number, which my seller did NOT provide me with. You ask them if it is possible to work it out from the information you’ve given them. They say no. You politely thank them for their help and you hang up in frustration. You pick up a random object and throw it across the room. In this day and age why is it so hard to send money across the world? WE HAVE THE INTERNET FOR GOD’S SAKE.

The next day, a Saturday, after running some errands you realise that it’s 11am and, thinking that the bank shuts at 12pm, you are in no particular rush. Out of interest you get home, go online and check to make sure the bank is where you think it is, only to see the closing time is actually 11:30am, and not 12pm. You race out the door and nearly forget to lock it. You speed off down the street nearly cleaning up the cars on both sides of the road and as you’re about to turn right to get out of the estate an old man driving a tiny car drives by. Doing 40.

You estimate that it’ll take you 20 minutes to reach the bank, doing the legal speed limit of course, but if you’re stuck behind this guy for any longer you probably won’t make it to the bank because you’ll:
a) Park yourself in his boot
b) Get pulled over for overtaking at higher speeds than what is most probably legal, all the while holding one hand on your horn and steering wheel and the other giving a one fingered salute.

You eventually decide that waiting for the guy to get off the road is most probably a good idea because you know within 5 minutes you will be on a 3-lane-wide main road in which you will be able to overtake the guy at 80 whilst he’s still doing 50. You tailgate this 4 foot, balding, head-super-close-to-the-steering-wheel asshole for the next five minutes, supressing the urge to smash into his right-back-side and spin him out of control so you can get to the damn bank, regardless of how much damage it would do to your 1986 Holden VL.

Finally you reach the main road! Only, most of the people on it think that it’s Sunday and drive like it’s a national day of mourning. You decide sticking to the speed limit is a good idea, since the cop in the left lane probably wouldn’t aid your cause if you decided to break the speed limit. You hang back, just behind the cop and in the lane next to him. Overtaking him is, to him, seen as a threat and he’ll probably pull you over for that bald front-left tyre and absolutely atrocious music you were playing. Eventually the cop turns off to the left and you carry on your merry way to the bank.

You reach the carpark. It is full. There are people in no rush what so ever holding the trolley with one hand and scolding their feral kids as they dawdle across the car park in front of you. Honestly, who would win? Your VL or a crappy aluminium trolley? They move off to the side and you plant your foot, but only enough for the wheels to spin for two seconds, and take a sharp left into the next column of the car park. You spy a park but some asshole’s already waiting and the guy pulling out of it doesn’t look like he’s going to be doing it any time this week. You look at the clock, mocking you from it’s position on your dashboard slowly ticking away, 11:18. You take the next column of parking and find that there’s not one, but TWO spots free. You don’t care what’s coming from what direction, you smack the indicator arm up and turn the wheel and park your car.

You enter the shopping centre and, since it’s a shopping centre you haven’t been in lately, you look for a map. There isn’t one, of course, so you walk around looking for this bloody bank and eventually stumble into it. The highly-motivated (read: not) employee on the other side of the inch thick plastic gives a mumbled “hello” and you mention that you would like to deposit some coins into your bank account. “Can I have your card please?” she asks. You hand her the card and then start taking the coins out of your bag. Once you’re done you zip up the bag and look up, only to meet with the iciest stare, you’re stopping her from going home. She weighs up whether or not to take your coinage and pelt you with it or to count it up. She decides that it’s not worth the effort to cause you bodily harm so she carries it all over to the little weighing machine they have. She weighs it all up and says that some of the bags didn’t have the right amount of coinage in it and the total was only $119.90. You mention you have one more order of business and as you reach into your bag you can just make out a sigh coming from the direction of the teller. You produce a piece of paper with all the account details on it for the international bank account and vaguely mention you want an IBAN number. She tells you that there is no way to work out an IBAN number from that information.

You leave the bank disappointed. You come home and google “IBAN Hong Kong Calculator” and find that there [url=http://creativeeyes.at/tools/iban]is a site that actually works out IBANs for you[/url] and you use that. You phone up the number again, this time knowing what to do to get a human to talk to you faster only to be told you can’t transfer money internationally because they don’t do that on the weekend.

I Has A Keyboards!

Wednesday, September 12th, 2007

Last week I saw a Rollup Keyboard on eBay and after wanting to try one for a while, I decided to buy it. After hearing “rave reviews” about how crappy it is, I REALLY wanted to try one and was happy to pay the $16.95 to buy it and get it posted to me.

Today it arrived. I was overjoyed, but food had to be eaten and my stomach was trying to devour itself, so I ate a lovely Ravioli first. During the course of eating the Ravioli I tried multi-tasking. This involved eating and attempting to type on the keyboard. Grab forkful of Ravioli, put in mouth and chew, type something, swallow Ravioli, repeat.

Let me start by saying this keyboard is… different. It has [url=’/images/rollup-keyboard/four-shift-keys.jpg’]four shift keys (two on each side)[/url], [url=’/images/rollup-keyboard/two-space-keys.jpg’]two space keys[/url], [url=’/images/rollup-keyboard/two-enter-keys.jpg’]two enter keys[/url] and [url=’/images/rollup-keyboard/two-blank-keys.jpg’]two blank keys that do nothing at all[/url]. However, it comes with a USB connector with a PS2 adapter attached, handy for plugging it into either socket. It’s automatically recognised by Windows, which is also a plus. It is also extremely quiet, with I would say at least 10 times less noise than my G15.

A few downsides are that it has [url=’images/rollup-keyboard/caps-lock.jpg’]this very bright red light[/url] which the company who manufactured the keyboard appears to have borrowed from the Terminator’s eye socket. The backspace key is about three keys further away than what I’m used to, thanks to the insertion of insert, del and pause/break keys. It’s also one key DOWN from the top-right edge of the keyboard where you would usually find it. Typing on it you have to press harder than expected and more accurately than you would on a usual keyboard, not that I type with any accuracy at the moment.
;
Here is me using it during a sandstorm just like the product description says

You’ll need sound for the full comic effect. The song in the background is Sandstorm by Darude.

If you are a novice keyboard user and look at the keys when typing, I recommend you buy this keyboard. It’s light, portable and seems useful in a way. If you are an advanced user however who does not look at the keys, you might be used to being able to touch the keys not quite in the direct center, and therefore you might find you make many more spelling mistakes on this keyboard than you would its larger, noiser brothers.

5/10

After initially writing this blog and using the keyboard for work I realised the total absence of both a Home and an End key. I wouldn’t mind if the two blank keys performed this action, but they don’t. It’s surprising how much you notice you need the home and end keys when you don’t have them.

RESTful Routes

Monday, September 10th, 2007

Eventually I hope to integrate this into the guide, but here it is.

RESTful routing makes it easier to link to the actions within controllers without having to repetitively type out code such as [term]:controller => “blogs”, :action => “show”, :id => blog.id[/term] every time you want to link to that specific action. RESTful routing also forces you into a CRUD convention (which may seem bad at first), but if someone reads your code they know what each action does. Restful routing, by default, employs seven actions within every controller, namely New, Create, Edit, Update, Destroy, Show and Index. These are the seven basic actions of your controller which nearly every controller uses. It also employs two more HTTP request methods, beside GET and POST, called PUT and DELETE.

We’re already have our blogs controller but we need to define a new line in our config/routes.rb

[code=”config/routes.rb”]
map.resources :blogs
[/code]

If we wanted to make a link to the blogs index somewhere, like application.rhtml, we would define it like so:

[code=”app/views/layouts/application.rhtml”]
<%= link_to("Blogs", blogs_path) %>
[/code]

This tells Rails that we want all the blogs, indicated by the pluralization of the word “blog”, and we don’t need to specify any further actions.

The line tells Rails that we want to make that controller RESTful. Previously, we have used [term]:controller => “blogs”, :action => “show”, :id => blog.id[/term] to go to a specific blog. Thanks to RESTful routing, all we now need to type is something like:

[code=”app/views/_blog.rhtml”]

<%= link_to blog.subject, blog_path(blog) %>

[/code]

This [term]link_to[/term] would use RESTful routing to take us to the blog. The way it does this is that it sees that it’s a standard link, so the HTTP request method is GET by default. It then sees that we want the path to a blog, defined by the singularisation of our controller which indicates we only want one blog. Finally, in the argument list after it we specify which blog. This can be the blog object itself (as shown in the example), or it could be [term]blog.id[/term].

To make a link to edit the blog, we call the method [term]edit_blog_path[/term] and specify the argument, which again can either be the blog object or the blog id, like this [term]edit_blog_path(blog)[/term] or [term]edit_blog_path(blog.id)[/term]. This will link us to [term]blogs/1;edit[/term]. This tells you simply that you’re looking at the first blog, indicated by [term]blogs/1[/term] and that you are performing the edit action on it, indicated by the [term];edit[/term].

Once we get to the edit form then we need to go to the update action. Here we would usually specify something like [term]:controller => “blogs”, :action => “update”, :id => @blog.id[/term] but not today! Instead we specify the form like:

[code=”app/views/blogs/edit.rhtml”]
<% form_for :blog, @blog, :url => blog_path(blog), :html => { :method => “put” } do |f| %>
[/code]

This says that we’re using the blog object, to go to the url of a single blog. Now here’s where it’ll get confusing. Before I’ve said that [term]blog_path(blog)[/term] goes straight to the show action within the blogs controller. Well, don’t worry, it still does. Just in this example I’ve specified [term]:html => { :method => “put” }[/term] which uses one of those custom HTTP request methods we saw earlier and instead of going to the show action it now goes to the update action.

Finally there’ll be a case where a blog isn’t just cutting it any more and we have to destroy it. This is where we use the final HTTP custom request method, [term]DELETE[/term]. To destroy a blog we specify a URL like [term]link_to “Destroy”, blog_path, :method => “delete”[/term]. Again, because we’ve specifed the method delete it doesn’t go to the show action, but the destroy action.

Now we want to define a new RESTful route for the comments for a particular blog and for that we’re going to define a nested route. This is just a route definition inside a route definition and isn’t really as tricky as it sounds.

In the routes.rb file replace [term]map.resources :blogs[/term] with:

[code=”config/routes.rb”]
map.resources “blogs” do |blog|
blog.resources ‘comments’
end
map.resources ‘comments’
[/code]

Notice how we have defined the route for comments twice. This is because we can either reference it by the blog’s nested route or by itself like [term]/comments/1[/term] to see the comment with the ID of 1.

This simply defines that we can call a route like /blogs/1/comments and ideally we would define something like the following in the comments controller:

[code=”app/controllers/comments_controller.rb”]
def index
@comments = Comment.find_by_blog_id(params[:blog_id])
end
[/code]

to get the comments for that particular blog. We can also now call methods like [term]comments_path[/term] to get all the comments universally or [term]comments_path(blog)[/term] to get all the comments for a particular blog.

To specify a custom action you can put [term]:member => { :custom => :get }[/term]
after the route definition to make it something like [term]map.resources :blogs, :member => { :custom => :get }[/term] Which will let you access the custom action by calling [term]custom_blog_path(blog)[/term]. To define something where you don’t need to pass in a blog argument, use [term]:collection[/term] instead of [term]:member[/term], like this: [term]:collection => { :custom => :get }[/term]. To define subsequent actions within these hashes, simply separate them with a comma [term]:collection => { :custom => :get, :other => :post }[/term] The symbol after the points to ([term]=>[/term]) is the HTTP request method by which the page is requested. You can use get, post, put or delete.

God And Why She’s Pissed

Friday, September 7th, 2007

I was talking to [url=/images/other/tom.jpg]Tom (file photo)[/url] tonight and the conversation went a bit like this:

[quote=”Conversation”](9:15:01 PM) Radar: I AM GOD.
(9:15:36 PM) Tom: no no your not
(9:15:44 PM) Radar: I like to think I am.
(9:16:04 PM) Radar: Regardless of whether SHE likes it or not.
(9:16:18 PM) Radar: I figure, if Satan is the “Prince of Darkness” and supposed to be opposite to God, then god must be the “Princess”
(9:16:19 PM) Tom: whos she?
(9:16:30 PM) Tom: lol i see
(9:16:37 PM) Radar: You’ve been insulting her.
(9:16:39 PM) Radar: She’ll be pissed.
(9:16:42 PM) Tom: lol
(9:16:48 PM) Radar: No wonder why she’s smote so many humans.
(9:16:52 PM) Tom: now that’s a different way of looking at it [/quote]

Also, you may have seen something about RESTful routes. That’s coming later. Also Rails Generators will rock your world. Two blogs coming up in the next week.

The Bike Ride

Sunday, September 2nd, 2007

Today for Father’s Day my dad and I rode [url=http://frozenplague.net/images/other/ride-2092007.jpg]this distance[/url] where 1cm is 500m.

In the future I hope to do a bike ride that my friend Ray and I did, which was down the River Torrens Pathway to the mouth, across to West Lakes and back up to Adelaide using Port Road (which just so happens to have the slightest incline and really kills you). The ride is about 30 kilometres long and [url=http://www.frozenplague.net/images/other/proposed-ride.jpg]goes something like this.[/url] On the lower right of the image where all the black lines converge is the train station.

Consider this an open invite. If you’re fit and willing to come, meet at the train station in town at midday (12pm, for the slow among you) in three weeks and bring your bike.

People Who Are Interested:
1. Me
2. Tom
3. Dad
4. Ray

People I should ask:
1. Paul
3. Eyerc people

People who aren’t going:
1. James (going to someone else’s wedding)
2. Joe (Full Schedule)