October 30, 2011 20:36

A few weeks ago my coworkers and I carved some pumpkins. I decided to make my favorite fluffy six-legged bison, Appa. I think he turned out pretty well!

Appa pumpkin from Avatar: The Last Airbender

News

October 1, 2011 21:35

I've done a few "manly" things with my car such as changing the battery, putting on a spare tire (more times than I'd like), and replacing the light bulbs. But today I completed my first home improvement - well, office improvement - project.

This is my surprise for the office on Monday - a wall rack for the darts we currently have scattered on the floor. Nothing special, but you have to start somewhere right? And there's something about drilling a hole into a chunk of wood that just feels so... right! :)

Homemade dart wall rack

News

September 20, 2011 13:49

I'm feeling pretty grateful this morning that I can wake up to views like this :)

Holy Name Cathedral in downtown Chicago

Chicago, Photography

September 12, 2011 01:41

Typically, when you try to divide by zero in MySQL, the result will be NULL. In certain cases, however, you'd like the result to be the numerator.

For example, when posts are receiving votes, we want a post with 8 yes votes and 0 no votes to have a ratio of 8 not of NULL. The cheap solution is to add +1 to both the yes and no votes, but then the ratio will be slightly inaccurate (9 in this case). The solution is to use MySQL CASE.

SELECT `posts`.`id`, 
    (CASE `vote_no`
        WHEN 0 THEN `vote_yes`
        ELSE (`vote_yes`/`vote_no`)
    END) AS `vote_ratio`
FROM `posts`

MySQL

September 8, 2011 16:47

If you have a table in MySQL with a Unix timestamp column (int 11) and you'd like to group results by date, you can run this simple query.

SELECT
    COUNT(`id`) AS `total`,
    DATE(FROM_UNIXTIME(`my_timestamp`)) AS `my_date`
FROM `my_table`
GROUP BY `my_date` DESC

If you want to group by month and year, ignoring the date, you can modify the query like this:

SELECT
    COUNT(`id`) AS `total`,
    MONTH(FROM_UNIXTIME(`my_timestamp`)) AS `my_month`,
    YEAR(FROM_UNIXTIME(`my_timestamp`)) AS `my_year`,
FROM `my_table`
GROUP BY `my_year`, `my_month` DESC

MySQL