Home Profile Projects Articles

Being Agile is my Favourite Thing

Saturday, 19 of April , 2008 at 1:40 pm

I got a real kick out of this video which I found on CodeSqueeze.

Leave a comment

Category: Programming

The Three Cardinal Sins when writing HTML

Saturday, 15 of December , 2007 at 11:14 am

I had an interesting conversation with our local web guru at work yesterday about web standards. Although there is a lot of “technically” valid syntax when writing HTML, it doesn’t mean that a competent web developer should be using them. The worst mistake a web developer can make is when he starts merging the layout of the page with the style of the page. While working at Discovery, this concept has constantly been drilled into my head. The HTML should contain the structure of the page and the CSS should contain style. As a web developer, you should consider anything that breaks this rule as a cardinal sin. From my experiences, I have ran into three cardinal sins when writing HTML.

  1. Do not use any tags which alters the style, size, or position of any elements. This is by far the worst sin you can commit when writing HTML. I should never see <center> or <font> on your site! This may have been acceptable for HTML 1.0, but is definitely not acceptable now. Even the thought of using these tags should make you feel sick because no competent web developer should use them.

  2. Do not use any tag attributes which alters the style, size, or position of any elements. Although this a little better than using tags, it isn’t by much. Although it is tempting to use the align attribute (or other similiar attributes) to define the position of elements, please resist! It may save you a little bit of time in the immediately future… however, you will thank me the next time you need to change the style of your site.

  3. The last cardinal sin is to write your CSS inline with your HTML. For the inexperienced, the reason why this is bad may not be immediately obvious. The big reason is because separating your CSS and HTML makes your site more orthogonal. The idea behind orthogonality is that different concepts should be as independent as possible from each other. If you want to change the style (CSS), the structure of the page (HTML) should not be affected. For more information about orthogonality (and other programming concepts), I would suggest reading The Pragmatic Programmer. This concept in web development is often called the Model, View, and Controller which should be applied, also, when programming in PHP (or something equivalent).

Like any “sinner”, I have committed all these sins (and continue to do so). I may not completely understand the zen of web development, but it doesn’t mean I should accept bad practices.

Comments (1)

Category: Programming

MacOSX: Creating a hard drive backup image

Thursday, 13 of December , 2007 at 12:32 pm

Recently, I have been having a lot of problems with my MacOSX machine at work. The machine contains multiple partitions each of which contains a separate server environment. Up to now, I haven’t been backing-up these partitions. This is a real pain when something goes wrong (like today) because it takes a day to re-configure a server on any given partition.

Anyways, to stop future pain, I’m starting to create compressed images of my partitions.

This is how I created my backups:


  1. Boot-up your system. Note: You can’t boot from the partition you want to backup.

  2. Start up the Terminal.

  3. Find the partition you want backup. You can use the following command:

    $mount
    
    /dev/disk0s9 on / (local, journaled)
    devfs on /dev (local)
    fdesc on /dev (union)
     on /.vol
    /dev/disk1s3 on /Volumes/Server1 (local, journaled)
    /dev/disk0s3 on /Volumes/Server2 (local, journaled)
    /dev/disk1s5 on /Volumes/Server3 (local, journaled)
    /dev/disk0s5 on /Volumes/Server4 (local, journaled)
    /dev/disk0s7 on /Volumes/Server5 (local, journaled)
    /dev/disk0s11 on /Volumes/Server6 (local, journaled)
    /dev/disk0s13 on /Volumes/Server7 (local, journaled)
    /dev/disk0s15 on /Volumes/Server8 (local, journaled)
    automount -nsl [176] on /Network (automounted)
    automount -fstab [180] on /automount/Servers (automounted)
    automount -static [180] on /automount/static (automounted)
    


  4. Unmount the partition/drive you want to backup. You can do this by throwing the partition/drive on the desktop to the trash can.

  5. Next, run the following command where src_name is the drive that you want to backup (ie. disk0s5 ) and dest_name is the drive you want to copy the backup to (ie. Server7)
  6. $sudo dd if=/dev/src_name
           | gzip > /Volumes/dest_name/backup.img.gz
    


If you need to restore the backup, you can run the following command.

$gzip -dc /Volumes/dest_name/backup.img.gz
      | sudo dd of=/dev/src_name

Note: There is probably a Mac tool somewhere that does the same thing if you scared of the command prompt.

Leave a comment

Category: Programming

Facebook Application: ‘Invite Friends Page’ code

Monday, 16 of July , 2007 at 8:51 pm

While doing contracting work for Trend Hunter, I wrote code for an ‘Invite Friends Page’. Since this is common to almost every facebook application, I decided to publish my code. You can check it out here. Please note that I “borrowed” some of the css and javascript from the X-Me application. I didn’t really want to waste my time writing the page from scratch.

Comments (7)

Category: Programming

Automatically Update all your User’s Facebook Profile

Wednesday, 27 of June , 2007 at 8:31 pm

While developing my first Facebook application, I spent a lot of time trying to get my application to auto-update everybody’s Facebook Profile. Majority of this time was wasted searching though discussion boards. Hopefully this will save you some grief.

You probably know by now that Facebook caches anything you post to a user’s profile. This means that you have to write a script which manually updates everyone’s profile. You might think that the reference tag would be the exception, but you would be mistaken.

Facebook will cache the following line:
<fb:ref url=”http://www.mysite.com/someurl.php” />

In order to clear the cache, you would have to execute this line:
facebook.fbml.refreshRefUrl(”http://www.mysite.com/someurl.php”)

Although using handles and references is a valid approach, I found it simpler to use profile_setFBML instead.

This led me to the next problem I ran into. When I started writing my auto-update script, I ran into the infamous “Invalid session key” error. In order to execute profile_setFBML, you need have a valid session key (you will need a valid session key for refreshRefUrl as well). This can be ANY session key! It doesn’t have to be the session key of the user’s profile you are updating.

Unfortunately, this isn’t as easy as using your own session key. Session Keys have lifespans, so we will have to create a special infinite session key. The first step is to create a new user for Facebook. Once you successful do that, install your application for your new user.

Next go to the following address and generate yourself an auth token:
http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY

Then pass your auth. token to your canvas:
http://apps.facebook.com/applicationname/?auth_token=YOUR_AUTH_TOKEN

When you are on your canvas, you will need to print your session key. You can do this by printing this:
<?php echo htmlentities($facebook->api_client->session_key); ?>

We can then use this key to update everyone’s user profile. Here is some example code (it should work).

Now that we have the script written, you will have to create a cronjob which will execute it on a given interval. I am not going to go into any details on how to create a cronjob. However, most web hosts allow you to do this easily.

As an important side note, you can’t use any infinite session key to publish a story or action (feed_publishStoryToUser or feed_publishActionOfUser). You will need a valid session key for the user you are performing the action on. This will force you to keep a record of valid session keys for all your users.

Comments (8)

Category: Programming, Tutorial