Stacked Notion

I’ve Switched to Octopress!

| Comments

Like most geeks in 2011, I’ve decided to make the switch to Octopress. Previously I was running a Wordpress installation that hadn’t been updated since early 2009 which I wasn’t too uneasy about. Plus I’ve also been meaning to consolidate a couple of servers for a while, and this makes it even easier as I don’t have to worry about moving the database. :)

At the moment I have imported all the posts and comments, however there are a few bits that need fixing. I need to go through all the posts at some point as images are broken and some of the formatting could be improved. Until then though, I’m afraid you’ll just have to suffer, so bear with me!

P.S. Apologies in advance in case anyone has any issues with the feed…

Take Risks

| Comments

This is going to be a bit different from my normal technical musings, so if that isn’t your thing, you should probably just skip now and wait for my next article (most likely something Erlang related). I like to thing that no matter how things are, you can always do better. As such I try and take every opportunity to broaden my horizons and learn something new. I’ve recently found Nerd Fitness, it is a Tim Ferris-esque fitness mixed with life improvement blog. This is a comment I left on the latest article Fail More, Suck Less:
Great article! I like the idea of a fail folder (if anyone has a link to the article give me a shout); it reminds me of Rejection Therapy (http://rejectiontherapy.com/). I actually tried the perfect 10 thing earlier in the week because of Rejection Therapy: I had been dragged along to a singles night and my mate was chatting to some girls who weren’t really my type. In most cases like this I usually just have a few too many beers and forget about my worries. This time I didn’t feel like getting drunk, and I also didn’t want to look like a loner standing at the side of the dance floor. As such I decided to just go and dance. There were a few other drunk people making fools of themselves so I figured I couldn’t do much worse. Also it definitely peeked up my mood. After that a few girls came and joined us, you know the type that look real nice but just want the attention. I started dancing with one of them, then got talking and to my surprise she wasn’t the attention seeker I expected, she was actually a really nice girl. Anyway, it ended up with us exchanging numbers and agreeing to go out with me tonight, wish me luck! I think the moral of this is that unless you take risks, nothing exciting is going to happen. Things are just going to stay the same as they are. If you take risks, even if you fail, you learn something, and next time you can use what you have learnt to improve.

Things That Should Work in IE That Don’t…

| Comments

For the first version of TextJs I “forgot” about Internet Explorer. I didn’t have a machine to easily test it on, and just wanted to get something out there to see whether the idea is worthwhile. I quickly soon got a complaint about this, so thought with the latest version I should fix that. I installed Windows 7 onto (into?) a virtual machine, here is what I got: Le sigh. I’m quite surprised that the Javascript works fine, but I’m using Backbone and jQuery for practically everything rather than rolling it myself, so that is probably why. The CSS though is a different story… I am also rather surprised about that as I thought Internet Explorer 8 was supposed to do a half decent job, I guess not. Below is what I discovered. “IE doesn’t believe in HTML 5 elements” Some of the CSS selectors applied to header tags, which IE doesn’t know about. As such it just ignores them. Adding the Javascript from html5 doctor solves that. This fixed the message date and hover-menu styling. Menu Highlighting This was actually my own fault rather than IE’s. I used the Ultimate CSS Gradient Generator to generate the code for the gradients, and for certain elements wanted to override it. This was easy, I just needed background: none (e.g. to remove it). However I missed that it also generated IE specific filter code. I also needed filter: none. Next… Menu Dates Unlike the message dates, the menu dates weren’t fixed with the teaching-IE-about-HTML5 Javascript file. Again the CSS rules being ignored were on header tags, however for some reason these were still being ignored. I couldn’t figure this one out, so I just moved the rules to other tags. Meh. Box Shadow CSS3 Generator, which I used for the other CSS3 effects didn’t supply a filter tag for the box shadow which IE supports, so this needed to be added:

background: #fff;
filter: progid:DXImageTransform.Microsoft.Shadow(color='#d0d0d0', Direction=135, Strength=3);
The background needs to be set, as unlike the CSS3 box shadow this also applies to any text on a transparent background. It also doesn’t support short hex colour codes, so #d0d0d0 rather than #ddd needs to be specified as the colour. Border Radius IE (below 9) doesn’t support border radius without some nasty hacks, either from Javascript or HTC files. I’m not that fussed about them so I’ll give that a miss. Keyboard Shortcuts For keyboard shortcuts I used Thomas Fuchs’ most excellent Keymaster. This is great and works cross browser no problems. The only issue is that most of the keyboard shortcuts I have in TextJs default to a browser function. I solved this in most cases (it doesn’t work for Cmd-N on Chrome >_<) by calling the jQuery function preventDefault on the event. This however doesn’t work in IE. Apparently this is the incorrect way to stop an event from firing the default action, however the solution is easy. Just return false from the event handler. I didn’t know about this before, and there are a few caveats (pointed out in the article), but for my use case this seems fine. It still doesn’t solve the Chrome issue though :-/ Console I had a few mischievous console.log’s left in place which caused a few Javascript errors. That is fixed with this nifty line of Javascript:

if (typeof console == "undefined" || typeof console.log == "undefined") var console = { log: function() {} };
I decided to add this rather than removing them as I’m sure more will appear later, so I would rather be safe than sorry. Roundup And there we go, let’s hope IE 9 is better. The fonts still look rubbish, but that is just Windows. For comparison this is what it looks like on Chrome on OS X. Aaahhh.

How to Setup Log Rotation for Rails Apps

| Comments

I’m sure we’ve all been there. You’ve been tasked with fixing a Rails app, you go in for some debugging magic and find the production.log is 3GB and counting as nobody bothered to setup log rotation. Here is how to avoid that… On Ubuntu machines (and I would guess most other Linux distributions) logrotate comes installed by default. To set it up, you just need to create a new config file in /etc/logrotate.d/, for example:

$ cat /etc/logrotate.d/tweetedlinks-backend 
/var/www/TweetedLinks/current/log/*.log {
    compress
    copytruncate
    daily
    dateext
    delaycompress
    missingok
    rotate 90
}
This tells it to rotate any logs with the .log extension in /var/www/TweetedLinks/current/log/. You don’t need to worry about permissions or restarting anything, just plonk that in a file and relax. Job done. In case you were wondering, here are what all the options mean:
  • compress - Compress rotated logs. zgrep and zcat are your friends.
  • copytruncate - Copy the log out of the way, and then truncate the existing logs. Some processes don’t handle log files being rotated, and will write logs to an empty file descriptor rather than the new log. This solves that.
  • daily - Rotate logs daily.
  • dateext - Add the date the logs were rotated as the extension rather than a number.
  • delaycompress - Skip compressing the log until the following day. Apparently some processes don’t handle logs being rotated properly and will write to the wrong file descriptor - n.b. does this even have any effect with copytruncate?
  • missingok - Don’t raise an error when there is a missing log file.
  • rotate 90 - Keep up to 90 days worth of logs. There doesn’t appear to be an option to not delete old logs, but you can just set this to a large number, like 36500 to keep 100 years of logs.
Discuss on Hacker News