Stacked Notion

Logos Quiz Is Genius

| Comments

Over the past few weeks all the app buzz has been about Draw Something and Instagram. Admitiedely good apps, but they’ve had their 15 minutes of fame. I’ve noticed over the past few days on Facebook a lot of posts about an app called Logos Quiz. I usually ignore most game posts on Facebook, and did the same with this, oh how I was wrong… I noticed this today:

#1 Baby

Yes that is right, it is #1 in the UK App Store, ahead of Draw Something (#6). It has 4482 ratings, nearly as many as the paid version of Draw Something (4735), and about half that of the free version of Draw Something (9727). Considering the app was only released a week ago this is pretty amazing.

Trending

The app itself is pretty simple, you are shown a logo of a brand and have to say what it is. There are a number of logos in each level, and you need to complete them all before you can progress on to the next. If you can’t guess the logo you can use one of your hints which you earn as you progress. You can also buy them as an in app purchase (69p for 120).

The genius of it though is the social interaction. Games such as Farmville let you post to Facebook to ask your friends for help, but require your friends to add the game before they can help you. This has a much lower barrier to entry, if you need help you can post the logo to your wall (or Twitter), and your friends just have to comment on the post to help you. Nothing to install, no need to worry about stealing your data, hence no reason not to help.

Genius

In my opinion the price of the in app purchases seems a bit low, I would probably do 10 hints for 69p. I’m also not too sure whether this falls under fair use for the logos, and I can see companies not being happy about the apparent association with the developer (although I expect that psychologically it can be argued that it is good that players are remembering the logos). I look forward to seeing what @AticoD comes up with next.

Further reading:

Easy Rails Daemons With Upstart

| Comments

Back in 2010 when I wrote TweetedLinks I needed a couple of daemons running in the background. I’ve used tools like God and DaemonKit before, but honestly they are more hassle than they are worth. I wanted something really simple that would play nicely with Bundler and not complicate development and debugging. At the time, at work I was working onan old Rails app, so I looked to see how that did it.

The daemons for this were just a simple Ruby script which included the Rails environment, and then a loop with a delay. Every 10 seconds they would check whether there was anything to be processed, and if so process it. This daemons were controlled by a simple init script. There wasn’t any automatic restarting if they died, but we used Icinga/Nagios to ensure the processes are running. So I took that as a base, and got something up and running. Here is an example of one of the daemons I have, I am using Stalker for queuing which handles the loop:

#!/usr/bin/env ruby
require File.expand_path("../../config/environment", __FILE__)
STDOUT.sync = true

Stalker::job 'user.fetch_details' do |args|
  begin
    user = User.find(args['id'])
    user.fetch_user_details!
  rescue ActiveRecord::RecordNotFound # too fast
    Rails.logger.warn "Unable to find user ##{args['id']} - suspect too fast, requeuing"
    Stalker.enqueue('user.fetch_details', :id => args['id'])
  end
end
jobs = ARGV.shift.split(',') rescue nil
Stalker.work jobs

I have this stored in the scripts folder and have it chmodded so it is executable. The import bit is the first three lines.

Next I wanted to make the script automatically start and automatically restart if it goes down. The first bit could be solved with init scripts, however restarting is the important bit. For the last few years Ubuntu has included upstart, which handles all this for you. The configuration for this is stored in files in /etc/init, it is pretty simple so take a look. Here is what I’m using for TweetedLinks in /etc/init/tweetedlinks-ruby-worker.conf:

description "TweetedLinks Ruby Worker"

# automatically start
start on filesystem

# working directory
chdir /var/www/TweetedLinks/current

# command to run, with Bundler support!
env RAILS_ENV=production
exec bundle exec ruby script/worker.rb >> log/worker.log

respawn

You can then start this with the command start tweetedlinks-ruby-worker, stop it with stop tweetedlinks-ruby-worker and check it with status tweetedlinks-ruby-worker. Simple right? This logs to the file log/worker.log in the Rails directory for the app, and I wrote a post earlier on how to setup log rotation.

Puppet: Setting Up and Using the Puppetmaster

| Comments

Over the past few months I’ve been working on using Puppet to automate my server setup. At the moment I only have one server, but it is still a pain to rebuild every few years whenever an old version of Ubuntu is discontinued. You can see what I’ve got so far on GitHub. Puppet seems like a great idea but documentation is absolutely appalling.

The tool itself has changed quite quickly, so a lot of old documentation isn’t relavent anymore and others (on the main site) has “not yet been written”. Hmm. It is also quite clear (not trying to flame, but anyway…) that the tool is built for sys admins not developers. This isn’t necessarily a bad thing as they are going to be the ones mainly using it, but if you just want to Get Shit Done™, you are in for one hell of a ride.

My previous attempts to use Puppet (see my GitHub repo for examples of both!) have been using Puppet under Vagrant (really nice, except I couldn’t find an Ubuntu 11.10 image… so I had to build my own) and using some custom magical single server setup (again, see the repo). I’m actually beginning to use Puppet across more than one server now though, so I wanted to setup Puppetmaster. This is basically a central repository to Puppet scripts, which shared them out to connected clients. As expected there was no documentation, so I wrote this!

Hostnames

Puppet uses SSL certificates to ensure that the client and server are who they say they are. This prevents your clients from receiving bad commands, and from your server revealing private data (MySQL root password) to untrusted hosts. For this to happen the client first talks to the server, and the server keeps it in a pending state. You then need to go onto the server and run a command to mark the client as safe. After that it will receive commands.

For this to happen firstly the time needs to be in sync between the boxes, and also the hostnames need to be the same on each (e.g. the master is master.home on both the master and client). As such you might need some /etc/hostname and /etc/hosts trickery.

Installation

Next up install the Puppet packages. Ubuntu versions lower than 11.10 have out of date versions, so don’t even bother installing those. If your host only provides images for older versions either move somewhere else or upgrade the installation once you’ve got the box setup.

All commands should be run on root, those denoted master should be run on the master, and those denoted client should be run on any clients (simple eh?).

master# apt-get update
master# apt-get install puppetmaster

client# apt-get update
client# apt-get install puppet

Start the master

When the mater is started it’ll generate it’s own certificate so make sure you have hostnames sorted by this point. Don’t worry if the directory you are deleting doesn’t exist, that it just to clear previously generated certificates.

master# rm -Rf /var/lib/puppet ssl
master# puppetmasterd --verbose --logdest console --no-daemonize

Start the client

The same notes apply to the master as the client.

client# rm -Rf /var/lib/puppet ssl
client# puppet agent --verbose  --logdest console --no-daemonize --server=master.home

After that, you should see the following on screen (as well as other stuff):

Client:
info: Creating a new SSL certificate request for client.home
info: Certificate Request fingerprint (md5): 0A:7B:EB:BF:63:E5:CC:92:03:96:28:43:65:59:08:3C

Master:
notice: client.home has a waiting certificate request

Verify client certificate

Next you need to verfiy the clients certificate:

master# puppet cert list
  client.home (0A:7B:EB:BF:63:E5:CC:92:03:96:28:43:65:59:08:3C)
master#  puppet cert sign client.home
  notice: Signed certificate request for client.home
  notice: Removing file Puppet::SSL::CertificateRequest client.home at '/var/lib/puppet/ssl/ca/requests/client.home.pem'

After a while…

The client automatically retries to connect to the master. You can either wait, or restart the process on the client. Then you should see this:

Client:
info: Caching certificate for client.home
info: Caching certificate_revocation_list for ca
info: Caching catalog for client.home
info: Applying configuration version '1327959635'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.03 seconds

Master:
notice: Compiled catalog for client.home in environment production in 0.02 seconds

Success

After that you’ll want to daemonize the processes, which should just involve some /etc/init.d trickery. After that you are done! Puppet scripts go on /etc/puppet on the master.

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…

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.