Here’s a thing.

You know how you’ve always felt a bit uneasy when you’ve passed a string into javascript’s new Date(), even when you know it’s in perfectly respectable ISO format?

Well it doesn’t work at all on my phone (Android 2.1 running WebKit 3.1).

Bummer.

Give new Date() a timestamp instead. Here’s some dirty python to generate just that:

    import time
    return int(time.mktime(the_date.timetuple()) * 1000)

We’ll fret about timezones later

My sleepy bunny

March 11, 2011

My sleepy bunny sleeps all day long
and whiles he sleeping he dreams up a song…
About a pirate who digs up some treasure
and whiles hes digging he starts to measure…
He starts to measure a telescope
filled with seweed and lots of hope…
The hope says “I’m not afraid
but please let me join your ambulance aid”…
The seweed said “Of course you can
but promise not to drive my little van…
Seweeds little ambulance had lots of chance
to rescue fish from the underground ants…
And the underground ants started to dance
to lots of pop and rock…
The ants like pop the best
and somtimes they wear their best VEST!

Ruby Miller

Peas with herbs and feta

September 21, 2009

Not sure of the provenance of this, I suppose it’s a bit mezze.
Oddly comforting though and a useful store cupboard standby.

Preparation time
5m
Cooking time
10m
Difficulty
1
Serves
4

I really must get a better camera

Ingredients
  • 600g frozen peas
  • 200g Feta
  • 4 tblsps nice olive oil
  • 2 spring onions
  • 1 bunch of parsley
  • ½ bunch of mint
  • ¼ bunch fresh oregano (optional)
  • Squirt of lemon
Preparation

Drop the peas in boiling water and let them come back up to the boil, leave them there for a couple of minutes, then drain.
Pour the olive oil into the warm pan and add the finely chopped spring onions. Swirl around a bit, then add the peas, the crumbled feta and the finely chopped herbs.
Add a grind of pepper and a squirt of lemon to taste.
Eat warm.

A smutty, filthy, dirty little shell script to toggle screen rotation on my netbook.

The results of xrandr -q will probably be different depending on what graphics set up you have, so adapt it to suit your needs. Compare the output of xrandr -q when the screen is in a normal rotation to it when it’s rotated right (xrandr -o 1 or xrandr -o right) and grep for the difference.

This is really useful when I want to read a long article or admire something in portrait mode. Now just need to work out how to rotate the trackpad input as well…

#!/bin/sh
if [ "`xrandr -q | grep 'current 1024 x 600'`" != '' ]
then
	xrandr -o 1
else
	xrandr -o 0
fi

We had a need the other week to churn out the skeleton of a site to see how the different areas fitted together.
As the thing was being written in Django anyway I put together this quick ‘n dirty utility that renders the reStructuredText docstring of a view to the returned response, so you can quickly put in page furniture and links to other views without having to go to the effort of creating templates.
Better still, as it’s implemented as a decorator on the method, it’s easy to swap out once you get around to writing the actual view code.


def docview(fn):
    from docutils.core import publish_string
    from django.http import HttpResponse

    r = HttpResponse(publish_string(
            source=fn.func_doc,
            writer_name='html'))
    
    return lambda rtn: r

Then decorate your method:


@docview
def fast_view(request):
    """
===========
A Fast View
===========

With links to:

 * `An even faster view </faster_view>`_
 * `Somewhere else <http://google.co.uk>`_
 
    """

Which will render something like:

A Fast View

With links to:

#!/usr/bin/env python
import sys, urllib2, twitter

def main(*args):
	try:
		t = twitter.Api('A_VALID_USER', 'A_VALID_PASSWORD')
		f = t.GetFriends(user=args[1])
		if any(u for u in f if u.screen_name == args[2]):
			print 'yup, %s follows %s' % (args[1], args[2])
		else:
			print 'nup, %s does not follow %s' % (args[1], args[2])
	except urllib2.HTTPError, e:
		if e.code == 404:
			print "soz, %s isn't a user" % (args[1])
		else:
			raise e

if __name__ == '__main__':
	if len(sys.argv) > 1:
		main(*sys.argv)
	else:
		print "who follows who?"

A hackity hack to find out if one twittard is following another.

You’ll need python-twtitter and simplejson, just do:

> python twit.py twittard1 twittard2

or stick it in ~/bin and chmod +x it, a la caolan’s suggestion

My cute and shiny little brown Acer Aspire One arrived today and very cute and shiny it is too. Did I mention it was brown? I’m writing on it right now dontcha know.

Being a twitchy geek I was switching Linux distros as soon as it came out of the box. It comes with the perfectly reasonable Linpus on it, which derives from Fedora 8. I switched to Easy Peasy though which is based on Ubuntu and has Debian packagey niceness all over it. You can find it here

It installed off a USB stick and after a moment of mild panic triggered by not being able to see any wireless networks (a reboot seemed to sort this out) everything was peachy.

One annoying thing (which is mostly the reason for this post) is that on reboot, the installer tries to do it’s thing again. This is to do with the Ubiquity installer being left in the session start up. To stop this go to System >> Preferences >> Sessions and uncheck Ubiquity in the start up programs list.

Whilst you’re there, if you want a more classical looking desktop, uncheck Maximus and Netbook Launcher.

But only if you want to you understand.

Follow

Get every new post delivered to your Inbox.