Tumble-Hybrid A-Go-Go

September 8

After months of saying ‘I’m going to do it’ I’ve finally made some alterations to jameswfrost.co.uk so it’ll act as a tumble-hybrid. That means it’s a combination of a normal blog (e.g. Wordpress-based) and a tumblelog (e.g. Tumblr-based). For me, it makes it easier to post short posts now and again, linking to pictures, videos, interesting articles, etc (and commenting on them) whilst at the same time still being able to write longer ‘proper’ articles as I did sporadically before.

For you, the reader, there should be more stuff to look at and read. Neat! If you’re not interested in seeing the things I stumble across as I look around the internet, you can view just the old-style articles (without the tumble-ness) in the articles section. There’s a feed of those available too. Planet SUCS now points at the articles feed (as I don’t want to fill it with tumble posts). If you currently only read this blog via Planet SUCS and you’d like to see the new tumble posts, then just subscribe to the main feed.

I still have a few tweaks to make here and there - posting digests of delicious links weekly, perhaps integrating Twitter somehow, but the basics are all in place. Enjoy!

Twitter Thoughts

August 13

I was just thinking about the problem of status updates, and multiple sites that allow you to post them, and the fact that most of us use Twitter and it’s generally pretty flaky.

I realised that a potential solution would be to have a kind of status update protocol, that all of the status update sites can conform to (some can have their own extensions, of course, such as pictures/locations, etc). Then people can host their own status update systems, much the way they host blogs now, or you can use one of the many ready-hosted services. The fact that all of these systems conform to the same protocol means that if, say, I used Twitter for my updates, I could still add you as a friend even if you were using your own self-hosted update system, and see your updates within my Twitter dashboard (and vice-versa).

Thoughts? Ideas? Anyone know if anything like this is happening already? Is there a big hole in my idea?

Losing

August 4

You may remember that back in May, myself and shepherdnick began a challenge to post one blog entry a day for an entire month, in an effort to get us writing more. Of course, the month deadline expired long ago - but how did we do?

In short, I failed miserably! I did well to begin with, keeping up with the contest and sometimes posting in the wee small hours of the morning in order to get a post in. And then I pretty much dropped off the radar. I think mainly I ran out of things I really wanted to write about (or at least, write reasonable entries about). I’m sure if I had more of a tumblelog-style blog (where I’d post links, videos, pictures that I’ve found and linked) I’dve had more than enough material to keep me going. However, I have now developed a backlog of things I want to post about and thought I’d best round off the contest before making a start on those.

As for Nick, he did fantastically - as far as I’m aware he only dropped a couple of days - and wrote some brilliant entries. Great job, Nick! You were an excellent rival! I owe you a pint/ice-cream/ice-cream-in-a-pint! :-D

The Items We Carry

June 8

Some time ago, I came across the Flickr group “What’s in Your Bag?” and so posted a picture of what was in my bag. It’s a bit of a shallow, materialistic meme, but hey.

That was 2 years ago, and I just stumbled across a similar (and seemingly currently popular) group on Flickr: The Items We Carry. Without further ado, I present my updated ’stuff’:

The Items I Carry

If you visit the photo on Flickr, you can rollover the items for an explanation, but I’ll replicate them here:

  • WHSmith Notepad + Fisher Space Pen: These go with me pretty much everywhere. The notepad is tiny, and acts as my GTD inbox. The Space Pen isn’t the best pen in the world to write with - it’s kind of scratchy - but it’s really small!
  • iPod Touch: I loves my iPod, I does.
  • Sony Ericsson K800i: This is a nice phone, and I really like the Sony Ericssons. However, my contract’s nearly up, so I’m hoping to switch to an iPhone soon. Then I’ll only need to carry one thing instead of two!
  • Keys: Lots ‘o keys. The carabiner is from when I watched the Calgary Hitmen play ice hockey when I was in Canada in my gap year.
  • Moleskine (plain notebook) + Pentel Hybrid Gel Grip pen: These are a very recent addition, but they’re both brilliant. The Moleskine’s really nice, and replaces an A5 WHSmiths pad I used to use but that all the pages kept falling out of. Being stitched, I’m thinking the pages will stay in the Moleskine :-). The Pentel Hybrid Gel Grip pen was a recommendation from Rands in Repose, and is excellent to write with.
  • Money + Cards: I rarely have my wallet with me (I don’t like the bulk in my pockets, so only have it if I have a bag with me), so I just carry these loose.
  • Inhaler: I haven’t carried an inhaler with me for ages, but my hayfever’s just started playing up a tiny bit, so I’ve started taking this with me.

I still use my tiny Gul rucksack that I showed in the original photo but it’s starting to show its age, and the zips are breaking a bit. If anybody knows of a nice, slim, A5 - A4 sized messenger bag/man-bag I can replace it with and fit this stuff in, please let me know! Also let me know if you do one of these photos yourself!

5 Artists, 5 Songs

June 4

Gareth tagged me to do Five artists, five songs, a blog meme.

List your five favourite artists, your five favourite songs by those artists and tag five other people to do it.

Read the rest of this entry »

Building Ruby 1.9 on Mac OS X 10.5 (Leopard)

June 3

I’ve recently been learning Ruby, and I wanted to install Ruby 1.9 on OS X to try out some of the new features (the current ’stable’ version of Ruby is 1.8.6). Unfortunately, I couldn’t find one cohesive guide to doing this, and instead had to mash together various instructions from across the interwebs. I’ve pieced everything together here in the hope that it’ll help out someone else. :-)

Step 1:

Firstly, readline needs updating, so grab readline 5.2 from http://ftp.gnu.org/gnu/readline/. After extracting it (tar xvzf readline-5.2.tar.gz) you’ll need to make one or two changes so that it will build correctly on Leopard. Simply apply this patch to support/shobj-conf in the readline directory you’ve created. The patch is necessary because readline currently doesn’t check for Leopard, only for earlier versions of OS X. In fact, the patch is simple enough that you could change the two lines by hand if necessary.

Then, configure readline, specifying a location so you don’t interfere with what’s already on your system, then build and install it:

./configure --prefix=/usr/local/
make
sudo make install

Step 2:

Next, you’ll want to download Ruby 1.9: http://ftp.ruby-lang.org/pub/ruby/1.9/. Again, we want to specify our own install location, and we also need to tell it where our newly installed readline is. We’re also specifying a program-suffix here (-trunk) so we can differentiate Ruby 1.9 from our pre-installed Ruby (so we’ll access 1.9 with ruby-trunk, irb-trunk, etc, and 1.8.6 with ruby, irb, etc).

tar xvzf ruby-1.9.0-1.tar.gz
cd ruby-1.9.0-1
./configure --prefix=/usr/local/ruby1.9 --program-suffix=-trunk --with-readline-dir=/usr/local --
make
sudo make install

Step 3:

Finally, because we’ve installed Ruby in a specific location, you’ll most likely need to add its location to your path. I have a bin/ directory in my home directory, so I simply have the following line in my .bash_profile:

# Add Ruby 1.9
PATH=$PATH:/usr/local/ruby1.9/bin

And you’re done. You can test by running ruby-trunk –version. Any problems, sound off in the comments. I may have missed something, as it’s rather late - and I could’ve almost certainly written this better. Hopefully I’ll revisit it in the future. If you get stuck, the articles I used to put this together might be of use:

Swapping Variables

June 2

I thought I’d share a little trick I learnt the other day regarding swapping variables.

A common coding/computer science task is to swap the values of two variables. In some languages, such as Java, one may start by creating a new temporary variable. For example (assuming we already have two ints, x and y):

int temp = x;
x = y;
y = temp;

This creation of a new variable uses more memory, and whilst in most circumstances would be fine, it could become an issue if we’re swapping many times, for example in a sorting algorithm.

Some languages allow us to do a nice swap without extra variables, using multiple assignment and tuple packing and unpacking:

x, y = y, x

This is pretty neat, although is apparently slower than using a temporary variable.

Anyway, yesterday I discovered a third method: XOR swapping. Again, this doesn’t require the use of an extra variable, and I thought it was pretty clever (here ^ represents XOR, as in Python):

x = x ^ y
y = x ^ y
x = x ^ y

Neat, huh? It’s fairly simple to see how it works if you simply walk through the steps. Let’s swap x = 7, y = 9:

x = 0111
y = 1001
x = x ^ y = 1110
y = x ^ y = 0111
x = x ^ y = 1001

Apparently this method is quite commonly used in embedded assembly code, however you won’t find it appearing much in code on a desktop computer. It usually is slower to compute than using temporary variables, as most processors attempt to execute commands in parallel - and of course, each of these instructions depends upon the previous result, so they must be executed sequentially. Still, it’s a nice thing to know.

The short version: it seems that if you’re trying to save memory then XOR swap or use multiple assignment, otherwise if efficiency is an issue, use a temporary variable.

Bookmarks and That

June 1

The other day I mentioned that I sometimes get into a bit of trouble when browsing the web, in that I end up having a huge number of tabs open, so I thought I’d blog a bit more about it. At the moment, I use several methods of bookmarking websites: del.icio.us to save urls for reference and and long-term recall (so, things I may want at some point in the future), Instapaper for things I haven’t finished reading yet, and then a combination of Safari bookmarks, Together, and keeping tabs open in Safari to remember stuff I’m researching or working on at the moment (so, things I will probably need sometime soon).

Obviously, using a multitude of systems for variations on the same task isn’t ideal. I’m sure it’d be possible to use del.icio.us in such a way that you could cover all these uses with the right selection of tags, however again I’m not sure this is ideal, and it’s not the intended use of the system. If anyone knows of a bookmarking system that covers most/all of these uses, please let me know!

My current plan is to implement my own system to solve this problem, and I figure it’d be a good excuse to put Ruby on Rails into practice to make a proper website. Intended features include: storage of bookmarks for a range of uses - each with an associated ‘view’ (these uses will include reference, research, and pages currently being read), tagging of bookmarks, and adding bookmarks via bookmarklets. I’ll let you know how I get on.

Apologies for the lack of links in this post - I’m currently in the pub on my iPod Touch and I can’t be arsed. I’ll add them when I get home :-)

FizzBuzz Follow-up

May 30

I thought I’d post a follow-up to yesterday’s FizzBuzz post with some sample solutions, as a bunch of you seemed to find it fun to solve. Feel free to add your own solutions in the comments of this post!

My own first solution was Python-based, and a fairly simple one:

1
2
3
4
5
6
7
8
9
for i in range(1,101):
    if i % 3 == 0 and i % 5 == 0:
        print "FizzBuzz"
    elif i % 3 == 0:
        print "Fizz"
    elif i % 5 == 0:
        print "Buzz"
    else:
        print i

Obviously it’s not in a function or anything, but I just wanted to do it as fast as possible. Shortly afterwards, I realised that line 2 could be simplified by changing it to:

2
	if i % 15 == 0:

Because of course, if a number is a multiple of 3 and 5, then it must be a multiple of 15.

Here are a couple of nice alternatives (ideas courtesy of Dave, although re-written by me because we didn’t save them). First, writing FizzBuzz as a iterator:

1
2
3
4
5
6
7
8
9
10
11
12
def fizzbuzz_generator(n):
	for i in range(1, n+1):
		if i % 15 == 0:
			yield "FizzBuzz"
		elif i % 3 == 0:
			yield "Fizz"
		elif i % 5 == 0:
			yield "Buzz"
		else:
			yield str(i)
 
for result in fizzbuzz_generator(100): print result

Then, a simple function to calculate the correct fizz/buzz, combined with a list comprehension to create the result (man, I love list comprehensions):

1
2
3
4
5
6
7
8
9
10
11
def fizzbuzz(i):
	if i % 15 == 0:
		return "FizzBuzz"
	elif i % 3 == 0:
		return "Fizz"
	elif i % 5 == 0:
		return "Buzz"
	else:
		return str(i)
 
print "\n".join([fizzbuzz(i) for i in range(1,101)])

Finally, here are two neat little Ruby one-liners, taken from the comments of the original FizzBuzz article. I hope the authors (Brendan, and Brian respectively) don’t mind me reproducing them here:

puts (1..100).map{|i|(s=(i%3==0?'Fizz':'')+(i%5==0?'Buzz':''))==''?i:s}
 
puts (1..100).map{|i|i%15==0?'FizzBuzz':i%5==0?'Buzz':i%3==0?'Fizz':i}

How neat is that? Anyway, as I said, feel free to leave your own solutions below.

FizzBuzz and Other Problems

May 29

Update: Check out the follow-up post for some sample solutions!

I love to code. Since a young age (I think I was about 7 when we first got out BBC B, and I would patiently tap BASIC code into the blinking prompt from childrens’ books about programming), I’ve loved to write programs. I read somewhere recently (unfortunately, I forget where) that it’s not the act of coding itself we love, but rather it’s solving problems that we love. I think that’s one reason I like learning new programming languages, as it allows me to solve problems in different ways.

A while back, I came upon the FizzBuzz idea. In short, it’s a simple exercise for employers to give to potential employees at interviews; a very simple exercise, yet one that someone will only be able to answer quickly if they ‘get’ programming. A suggested FizzBuzz problem is the following:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

I invite everyone reading this to have a go now - time yourself, and see how quickly you can do it. Unfortunately, I only timed myself by looking at the clock, but I was glad to have completed it in under a minute. Apparently this shows I can code:

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary ? - the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.

That is a scary thought, but I expect it’s almost certainly true.

So, this sort of simple problem excites me - I can work out a solution, and then try and improve that, perhaps. Myself and Dave spent a fair while earlier today trying to come up with more and more sophisticated solutions. And y’know what? It was fun!

On a similar note, I thought I’d mention a website that I found a while back (thanks to Matt Gwynne) that might be of interest to anybody else who enjoys these kind of problems. Project Euler is “a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve”. It contains a list of (at the time of writing) 195 mathematical problems, and the aim is to write code to solve them. You can then put in your answers, the website will tell you if you’re correct, and check them off the list. Great fun, and it’s neat to see some of the interesting solutions that people come up with (and the range of languages they use!). Hooray for being a geek! \o/