You are viewing [info]robinw's journal

Robin Ward

> recent entries
> calendar
> friends
> My web based online RPG
> profile
> previous 20 entries

Monday, January 22nd, 2007
12:16 pm - Learning Haml

Originally published at Robin Ward's Blog. Please leave any comments there.

Haml is a templating language for generating views in Ruby on Rails. It was created by Hampton Catlin, who I’ve met a couple of times at the Rails Pub Nites in Toronto. I’d made a mental note to check it out for some time, but I’d been quite lazy about it. Last week Hampton told me I was basically a douche bag (my words, not his) for not spending the 20 minutes it should take to learn it, and that he guaranteed it would make me a faster developer.

It is a great little language, and has not only made templating faster once I got into it, but also much cleaner. Anyway, I did encounter a few “gotchas” when learning it that I didn’t see documented on the site, so I figured I’d blog them here.

Inline Formatting

Haml is great at the majority of formatting you’ll do in a rails application, but for applying mark up to certain words or sentences in a paragraph, or inlining links it’s not quite so good. For example, let’s say you wanted to format a sentence like this:

Joanna Newsom is the worst singer I’ve ever heard. Wow she sucks.

There are helpers to achieve this in a somewhat unelegant fashion - but really the better solution is to just inline your formatting tags. While it appears to break the structure of Haml on some level, it’s far more readable and workable. Hampton himself even agrees:

For me, I’m totally fine with inline formatting tags being HTML. They don’t really bother me.

The main reason is that Haml is for structure, not really formatting.

Here’s how I’d write that sentence:

%p Joanna Newsom is the <b>worst</b> singer I've ever heard.  <i>Wow</i> she sucks.

Rails 1.2 style Forms

In Rails 1.2, the preferred syntax for forms is:

<% form_tag do |f| %>
  <%= text_field 'account', 'name' %>
  <%= submit_tag 'Save that sucker' %>
<% end %>

This might be obvious to some, but I found my forms were repeating twice because I used the = operator to open them. The correct way is to use the - operator (Note that the tag is not closed: HAML is smart enough to do this automatically using the indent!)

- form_tag do |f|
  = text_field 'account', 'name'
  = submit_tag 'Save that sucker'

Cycling

I can’t stand to look at tables in HTML unless the rows have alternating colours to make it easy to line up the data you’re looking at. Rails has a great function for this called cycle that you can use like this:

<tr class="<%= cycle("even", "odd") %>">

For some reason, it wasn’t obvious to me that HAML’s attributes for tags can evaluate Ruby code, so I sat around for a minute or two trying to figure out how to mimic this. After I realized that I could put code in there, the syntax was really obvious (and elegant!):

%tr{:class => cycle("even", "odd")}

Much nicer eh?

Thursday, January 18th, 2007
11:08 am - Reading stuff about Atheism

Originally published at Robin Ward's Blog. Please leave any comments there.

I’ve been reading more since I started working from home. My theory for why this is happening is because I don’t feel pressure to go to sleep by any specific time, so I’ll just keep reading for much longer than I usually do in a stretch.

I finished Sam Harris’ Letter to a Christian Nation the other day and loved every page of it! The title is a misnomer, though. The target of the letter is definitely the Atheists and Agnostics, as each section is full of arguments to counteract something a Theist or Deist might tell you. It’s a lot shorter than his last book The End of Faith and goes through some of the same arguments, but I think it works better. It’s more concise.

Fun Bible fact: If you find out that your wife is not a virgin on your wedding night, you should bludgeon her to death on her father’s doorstep. Oh, and thou shalt not murder.

Now I’m working my way through Richard Dawkins’ book The God Delusion. It’s great so far and I’ve already learned quite a bit. Maybe I’ll post a little more about it when I finish the thing.

Monday, January 15th, 2007
1:16 pm - Santa be a straight up playa

Originally published at Robin Ward's Blog. Please leave any comments there.

Late last year, Drach, Paul and I entered a contest on Sick Animation to create a Christmas themed rap.

Before you download this, I should warn you: Like the content on Sick Animation, It’s offensive. This is not suitable for young audiences. If gratuitous descriptions of sexual acts offends you, do not download it. If a white guy saying the word “n*gga” ironically offends you, don’t download it. On the other hand, if you’re not offended easily, go ahead and download it and have a laugh or two!

I wrote the first half or so of the song, then Drach and Paul helped me fill out the second half. The rapping is all done by Drach and myself, and Paul did the production side of things. During post-production, we decided to pitch shift my voice down slightly. At the time I thought it sounded cool, but in retrospect I think I sound a bit like a transvestite.

P.S. We lost the competition.

Saturday, January 13th, 2007
12:36 pm - Identifiable

Originally published at Robin Ward's Blog. Please leave any comments there.

After I got home last night, I realized that I’d left my bag at the bar with a bunch of poets. I frantically called my friend Dave a couple of times hoping that he was still there, but he didn’t answer his cell phone. I considered taking a cab back to the bar but it was half way across town and since I don’t have any regular income these days I’m trying to cut back on expenses.

Just now, Dave called me, saying he found my bag. I didn’t leave him any messages, but he was able to discern that the bag was mine based on its contents alone! I guess I’m fairly predictable. The bag contained two books: A biography of Steve Jobs and pop-Atheist Sam Harris’ Letter to a Christian Nation.

If you lost your bag, do you think your friends would recognize it was yours based on the contents alone?

Friday, January 12th, 2007
11:33 am - Crotch Zombie Update

Originally published at Robin Ward's Blog. Please leave any comments there.

Fun stuff: If you Google Crotch Zombie, you’ll find the first result is our wonderful site. Sure, it’s an odd combination of words, but it’s still awesome that before releasing a single product we’ve topped Google.

The second link is to Urban Dictionary’s definition of the term. You’ll notice that the top entry is also our work:

A sexually discomfiting prank whereby the actor, in the presence of several others in a confined area (such as an elevator), covers his crotch and proceeds to slowly and steadily approach the victim, impressing his pelvic region upon him, moaning and assuming the blank expression of the walking undead (i.e., a zombie).

The purpose of this is to annoy the victim while providing amusement for friends or bystanders within the confined area. If more than one person joins in on the proceedings, it becomes a crotch zombie swarm.

The purpose of covering the actual crotch with one’s hands is to provide a physical bulwark of heterosexuality, or no homo

Man, I crotch zombied Steve real bad in the elevator the other day.

Thursday, January 11th, 2007
12:54 pm - Science Test

Originally published at Robin Ward's Blog. Please leave any comments there.

Here’s a question for you: What orbits around the earth?

Apparently the answer isn’t so obvious. (note: the video is in French, but should be easy enough to understand). Thanks to my Dad for finding it. For fun, ask your co-workers and friends and see what they answer!

Here’s another question: Is there such a thing as psychic power? Here’s a video of a famous one on a talk show.

I can say that I definitely learned that the moon orbits the earth in school (not to mention countless other places), but the subject of psychics never really came up.

The difference between pseudo-science and regular science is not very complicated. I don’t see any reason why we aren’t teaching this to children in grade school once they start taking science classes. On the second day in class, after they have learned the basics of the scientific method, why don’t they put up a list of things that there are no scientific evidence for? They don’t have to say “These aren’t real” but simply, “There is no scientific evidence for the following”

  • Astrology/Horoscopes
  • Psychics
  • Ghosts
  • Reflexology
  • Magnetic Therapy
  • God/Creationism/Intelligent Design
  • Prayer Healing
  • Most chiropractic treatments
  • Luck
Wednesday, January 10th, 2007
6:36 pm - New Television

Originally published at Robin Ward's Blog. Please leave any comments there.

Last week, after a particularly grueling day working on my venture, J and I decided to log into Xbox Live and finish our Hardcore campaign of Gears of War. We hadn’t even been playing a minute when the picture on my television went awry. All of the blues started to bleed in a weird wave-like formation. I tried to adjust the cables and the convergence on the set but it was definitely busted in a bad way.

It couldn’t have come at a worse time, really. I was super stressed from working all day and just wanted to unwind, and I’ve been trying to spend less money since I don’t have any regular income right now. I put in a call to a service place over the weekend and got a call back on Monday, then I called a couple of other places before realizing it was going to cost me around $560 to repair the TV. I figured that was more than the re-sale value, so I made an impulse decision to buy a new set.

I did some research on the net, then had my dad drive me to Best Buy to buy the set. This time I got a LCD screen so I don’t have to worry about burn in when playing video games, and it’s much sharper and brigther than my old set, not to mention the viewing angle is amazing. Unlike my previous set, it doesn’t matter if you’re standing up or sitting down. Oddly enough, the viewing angle thing wasn’t much of a problem in the past - it’s only in the last year since I picked up guitar hero and my Wii that people have wanted to stand while playing!

Monday, January 8th, 2007
4:23 pm - Multiple onLoad events in Javascript

Originally published at Robin Ward's Blog. Please leave any comments there.

Most web developers are familiar with the onLoad event of the <body> tag that enables some Javascript code to be called when a HTML document is fully loaded. It’s useful if you want to manipulate the DOM in some way once the page has already been generated.

It’s quite common when coding a web application to want to separate the page segments into a ‘header’, ‘body’ and ‘footer’ type of layout. Unfortunately, this almost certainly means that the <body> is outside of your normal domain of work. You can get around this with some clever code, perhaps setting a variable that your header template will check and evaluate if an onLoad event is required.

But even then, there are other situations where you might want to add an onLoad in the body of your page, when you aren’t aware if there is already an onLoad event present from some other Javascript library you’re using, or that was in the header in the first place.

Here’s another piece of Javascript code from my Top Secret Project(tm) that will allow you to register multiple onLoad events to your documents:


function register_onload_function(f)
{
	if (window.onload == null)
	{
		window.onload = f
	} else {
		var old_unload = window.onload
		window.onload = function (e) {
			old_unload(e)
			f(e)
		}
	}
}

Calling it is pretty simple. Simply pass it a function pointer in a <script> tag somewhere:


<script>
var first = function() { alert('first call!') }
var second = function() { alert('second call!') }

register_onload_function(first)
register_onload_function(second)
</script>

Sunday, January 7th, 2007
7:13 pm - Skating at Nathan Phillips

Originally published at Robin Ward's Blog. Please leave any comments there.

Today I went skating at Nathan Phillips Square with a bunch of friends. There was a time, back in high school, where I was going skating about once a week throughout one winter. I figure that was about ten years ago.

I ponied up my $9 for the skate rental, tied them on tight and stepped out onto the ice. The second my blades hit the ground, I knew that I’d made a mistake. My knees were completely wobbly, and I had no idea how I was even going to stand in place let alone skate. But then I started out slow, and eventually gained the confidence to go around at more than a snail’s pace, and had a blast!

It seemed to get much busier after an hour or so. Skating around meant being in a tornado of people, but I quickly got used to it. I didn’t even fall! At one point, some kid checked me, and I was about to go down, but then I grabbed Mike Shea for support. It’s pathetic, I know, but it meant not hitting the ground. “I’m there for you man” he said. “No Homo!” I said back.

Now I’m toying with the idea of getting a pair of skates and going back for exercise!

Saturday, January 6th, 2007
5:18 pm - If you believe in Scientology you’re dumb

Originally published at Robin Ward's Blog. Please leave any comments there.

There, I said it.

I know we’re supposed to practice religious tolerance, but I can’t even fathom how someone could be interested in a religion like Scientology. Drach pointed me to a Buffalo Beast article on the “religion” and it’s hilarious. Here’s a quote for those too lazy to read TFA:

Neil is an okay guy, in a used car salesman sort of way. He sat me down at a desk, delving into my personal life. It was soon determined I lack the self confidence to succeed. “This course is only $82.50,” he said, “and it will change your life.” I simply didn’t have the cash. After various sales techniques proved futile, Neil did his best Ben Stiller from Starsky and Hutch. “Do it,” he repeated over and over. “Do it.”

“But I…” “Do it.” “But…” “Do it.” “Bu…” “Do it.” “B…” “Do it.”

He said it nearly 20 times.

Friday, January 5th, 2007
3:23 pm - Dan Gilbert on Synthetic Happiness

Originally published at Robin Ward's Blog. Please leave any comments there.

Steve pointed me to one of the TED talk videos that I hadn’t noticed before. In it, Dan Gilbert talks about happiness. In particular, he talks about how studies have shown there’s a huge disparity in terms of what people think will make them happy and what actually does. The most intersting part, in my humble opinion, is where he talks about how synthetic happiness is every bit as powerful as actual happiness.

The video is about 20 minutes long, but you only have to watch about 5 minutes to get the idea. If you’re not hooked by that point, feel free to shut it off and move on with your life. I found it almost enlightening. I haven’t been able to get the ideas he talks about out of my head since.

Thursday, January 4th, 2007
4:28 pm - Music Things

Originally published at Robin Ward's Blog. Please leave any comments there.

Intervention

I just bought the latest single from The Arcade Fire off of iTunes. It’s called Intervention, and it’s phenomenal. It’s a solid rock song, but it’s layered on top of this gigantic pipe organ from a church somewhere in Montreal. It gives it this feeling of being bigger than life, and that’s even before the backup vocals roll in. Here’s what Scott Colburn, the producer/engineer on the new album, had to say about it:

“The band went into the church ahead of me and my assistant James Ogilvie,” Colburn wrote. “They recorded a sample of the organ playing a chord in different registers. Win called me and told me how excited he was about the organ. He said is [it] was super loud and so overwhelming that it brought a tear to his eye. I promptly called him a pussy.

“When I first walked into the church and saw the organ, I just stood dead in my tracks. ‘Now THAT’s a fucking pipe organ!’ I thought… During the first take, I became overwhelmed by the grandeur of the whole thing. I heard that piece in it’s finished state and it was magnificent! Tears rolled out of my eyes. I don’t know what came over me, but it was a complete emotional release. The problem was that there were mics all around me, so I really couldn’t sob. So I’m trying to hold back any kind of vocal component to this overwhelming joy I was experiencing.

Sirius Satellite Radio

My dad bought me a Sirius satellite receiver for Christmas this year. I eagerly hooked it up the next day and I’ve been listening to it ever since. I used to listen to the radio a lot while working when I was back in high school, but with the advent of the Internet and music downloading, I got sick of their limited selection and intrusive advertisements. Satellite radio gets rid of those two constraints, and I’m in love with it. If you like listening to music while you work and are looking to be introduced to new artists in the genre of your choice, I highly recommend it.

Tuesday, January 2nd, 2007
5:04 pm - How to stop scriptaculous from firing events when dragging

Originally published at Robin Ward's Blog. Please leave any comments there.

script.aculo.us is a great javascript library if you’re interested in rich interfaces on the web. I’ve been using it for months now and it’s great. One thing that I love is the ability to drag and drop page elements around. However, I encountered a problem a few months ago that I was unable to find an elegant fix for.

Let’s say you’re using an absolutely positioned div as a pop up window. The user can drag it around by clicking and holding on the title bar while moving the mouse. When they are ready to drop it, they simply let go of the mouse and the window stops moving. Pretty simple stuff right? In scriptaculous, coding such a thing is generally easy: simply make the div of your pop up window a Draggable. Let’s say your window div is called popup and the title bar you’re dragging is called popup_title:

<script language="javascript">
new Draggable('popup', {handle: 'popup_title', revert:false})
</script>

Now it’s quite common in user interfaces for windows to have a little X (close) button on the top corner so that you can click to close them whenever you’re done with them. Implementing a close button is pretty easy as well in script.aculo.us:

<div id="popup_title">
<a href="#" onClick="Element.hide('popup')">x</a>
</div>

Everything seems to be working great, right? With very little code you have an awesome little window you can drag around and close whenever you want! However, if you try clicking and holding on the close button (in this example it’s just the character x, but it’s likely you’d want to use an image), you’ll notice you can drag the window using it. Pretty neat side effect eh? However, what happens when you let go of the mouse button after dragging it? Oops! The window closes! That’s not right!

What’s happening here is not a bug in the way script.aculo.us works. What’s happening is that the events are on a chain. After it stops dragging, it calls the next event in the chain which is the close button, closing the window. What we’d really like to do in this case is stop the event loop. I googled for an easy way to do this and came up empty handed, so I ended up coding my own little Singleton object, called StopFiring, in stop_firing.js

Download stop_firing.js

StopFiring has but one method, you. You call it with with the id of the handle you are dragging and the id of the parent object that is being dragged. Include the javascript file at the top of your page. Then, after declaring a Draggable as in the example above, add a call to StopFiring.you:

<script language="javascript">
new Draggable('popup', {handle: 'popup_title', revert:false})
StopFiring.you('popup_title', 'popup')
</script>

Note that the second parameter is optional. If you’re dragging the same thing you’re moving (for example, a button that you don’t want to click the second you let go), just call it with that one argument.

Monday, January 1st, 2007
12:53 pm - Freddy got Fingered

Originally published at Robin Ward's Blog. Please leave any comments there.

Tom Green’s directorial debut, Freddy got Fingered, has one of the worst overall rankings on Rotten Tomatoes. The movie was downright HATED by the critics.

I’m not sure why I decided to check it out; at some point in time someone must have told me it was worth a look. And since I’ve noticed that there have been other times when I’ve loved movies that were panned, I gave it a shot.

I’m not sure what to feel.

The movie goes on a bit long, but I have this odd feeling in the back of my head that Tom Green is some kind of insane genius, and that the movie is some kind of elaborate joke on the movie industry. I have no idea how he managed to convince the studio big wigs to allow him to shoot some of the things he did. For example: Tom Green is driving down the street, and sees a horse with an erect penis. He slams on the brakes, then runs over and masturbates it. This is done without any foreshadowing, explanation or consequences.

It’s twisted, disgusting, outrageous and on some level, funny.

Wednesday, December 27th, 2006
10:43 am - Watchmen

Originally published at Robin Ward's Blog. Please leave any comments there.

Last year my brother bought me a copy of Watchmen for Christmas. It sat for ages on my bookshelf as I read through other books that I’d been given, and I finally cracked it open a day or so before Christmas this year.

I couldn’t believe how much I loved it. After reading 3-4 of the chapters in the graphic novel I already knew it was the best comic book I’d ever read. I finished it last night, and then spent the morning reading up on it (and the movie adaptation that it’s in the works) on Wikipedia.

It’s funny how sometimes the books that are low on my totem pole in terms of desirability to read can actually be the best!

Monday, December 25th, 2006
10:54 am - Fun with Photobooth

Originally published at Robin Ward's Blog. Please leave any comments there.

Last night (Christmas Eve) I showed my niece the photobooth application on my MacBook. She thought it was the coolest thing, so we snapped a bunch of pictures:

silly-2.jpg

The descent into silliness begins:

silly-3.jpg

She liked the way my glasses looked, so she got a pair for herself:

silly-4.jpg

And finally, us both making monster faces:

silly-1.jpg

Merry Christmas everyone!

Sunday, December 24th, 2006
11:31 am - The best thing I’ve ever heard

Originally published at Robin Ward's Blog. Please leave any comments there.

My dad sent me an email this morning:

Subject: Oh my gawd

You have just got to listen to this……. link

pa

Take his advice and click the link! If it doesn’t get you in the Christmas spirit, nothing will!

Saturday, December 23rd, 2006
9:30 pm - Neckbeards and Cardigans

Originally published at Robin Ward's Blog. Please leave any comments there.

I have to say, I never thought I’d be one of those guys. You know, those who listen to indie music and have neckbeards and wear cardigans in the summer time. But over the last year I’ve really fallen in love with indie music, to the point where I don’t really listen to much of anything else. Here is some of the music I loved the most in 2006:

It’s worth noting that more than half of those bands are Canadian. I swear that’s not me being patriotic or anything, Canada’s indie scene is just thriving these days.

P.S. I stopped getting emails about comments to moderate on this blog because I was screwing around with my server’s settings. I published everything in my queue now, so if you were wondering why your comment didn’t go live, you know why now.

Thursday, December 21st, 2006
5:36 pm - Scale

Originally published at Robin Ward's Blog. Please leave any comments there.

How often do you think about your size? I find it a good mind exercise to explore once in a while.

The Big

This Video is humbling. It demonstrates the size of the Earth relative to other known bodies in the universe. We’re often told we’re very small, but it’s interesting to visualize exactly how much.

The Small

The majority of the universe is empty space, even if we don’t perceive it as such. The table my arms are resting on right now is solid, but if you were to look at it through a microscope you’d find that it’s really quite empty. Take a hydrogen atom (the most abundant element in the universe) as an example. The majority of its mass is in the nucleus, which is 1 / 100,000 of its total size. According to Wikipedia, if a hydrogen atom were blown up to the size of a sports stadium, its nucleus would be the size of a marble. There are other things that make up an atom too, such as electrons, but they don’t make up for the vast empty space that appears solid to our senses. If you blew up the hydrogen atom to be the size of the earth, the electron would be less than 10cm in size!

Wednesday, December 20th, 2006
2:09 pm - Christmas Time and Best Movies

Originally published at Robin Ward's Blog. Please leave any comments there.

Christmas snuck up on me yet again. I don’t even have to buy presents for very many people, but I still manage to always leave it until the last minute. Fortunately last night I wrapped up my gift buying, and now I can just relax and avoid the malls like the plague.

It has occured to me that as an Atheist perhaps it’s not appropriate that I celebrate the birth of Christ. However, beyond the date, I don’t think there’s much Christianity in what we do. We have a tree (pagan symbol), presents (capitalistic giving-innery) and turkey (gluttony). Not a single prayer will be uttered. No reference to God will be made (unless it’s ironic). I’m quite content to bastardize the Christian holy day.

The real fun of my business venture is so close I can taste it, and it’s driving me crazy! Before I know it, I’ll be working from home all day, creating some (hopefully) awesome stuff!

I like creating “Best Of” lists. Here’s the best movies I saw this year:

Little Miss Sunshine
The Queen
The Departed
Marie Antoinette
Clerks II
Jackass 2
United 93

If I had to pick a “Best Picture” I’d say that would have to go to Little Miss Sunshine.


> previous 20 entries
> top of page
LiveJournal.com