Round the houses, Linux video editing
Since I've upgraded to Ubuntu 10.04, I figured this would be a good time to play with video editing, which is something I've been wanting to play with for a while. I suspect that video editing could be a killer app for Linux, and there are a few packages to chose from. Kdenlive looked to be the most feature rich, but I'm afraid I found it buggy and prone to crashing, so I settled on OpenShot, which has a clean, simple interface and didn't crash on me once.
Here's the video I put together:
If you know the answer, please don't post it straight away – to give others a chance to figure it out…
No audio in Flash on Ubuntu 10.04
Upgrading to Ubuntu 10.04 went remarkably smoothly, with the exception that audio in Flash was erratic. Sometimes it worked, sometimes it didn't. Since I use my PC as an entertainment system, this was pretty much a deal-breaker.
Googling for it got me no where. Apparently “no audio in flash” is the Ubuntu equivalent of “i have a headache” – it's a vague symptom that has multiple possible causes. Long story short, the problem was that I had both Flash 9 and Flash 10 installed. Firefox appeared to pick one at random (as far as I could tell), but audio only worked with 10. The solution was to delete Flash 9 – which I couldn't do from the package manager, because it turned out I had Flash 9 installed locally.
If this sounds familiar, type about:plugins in to the Firefox address bar. If you see two entries for Flash, then give the following a try:
rm ~/.mozilla/plugins/libflashplayer.so
This is probably the result of some tinkering I did before upgrading to 10.04. I doubt this will be a problem with a fresh install.
Damn foreign keys, stealing our jobs and women
Django has support for Generic Foreign Keys, which let you reference one model instance from another, without knowing up-front what that model type is. The classic use for something like this is for a commenting system; you need generic foreign keys – or something like them – because you wouldn't want a commenting system that only worked with a single model.
If you have ever used generic foreign keys in Django, you will know that it is not quite transparent to the developer; a little effort is required to manage the various content types. I'll present here an alternative method to achieve this late binding of foreign keys that doesn't require storing the type of the object (as generic foreign keys do) and is completely transparent to the developer. I'm sure I'm not the first to think of this method, but I haven't yet seen it used in other Django projects.
Rather than store the type of object in a separate field, we can create a new model for each foreign key type we want to reference. For example; lets say we have a Rating model, and we want to rate Articles and Images – we could do this by generating a ArticlesRating model and a ImagesRating model with appropriate foreign keys. The easiest way to do this is with a function that returns a parameterized class definition.
Here's a snippet of code from a project I'm working on, that does just that:
rating.py
from django.db.models import Model, ForeignKey, IntegerField, Count, Avg from django.db import IntegrityError from django.contrib.auth.models import User def make_rating_model(rated_model, namespace): class Rating(Model): user = ForeignKey(User) rated_object = ForeignKey(rated_model) vote = IntegerField(default=0, blank=True, null=False) class Meta: abstract=True db_table = u'rating_%s_%s' % (namespace, unicode(rated_model).lower()) unique_together = ('user', 'rated_object') def __unicode__(self): return u"%s's rating of %s" % (self.user.username, unicode(self.rated_object)) # Rest of the methods snipped for brevity # Contact me if you would like the whole class return Rating
This isn't a model definition, rather it is a function that create a model definition. You can call it multiple times to return a Rating model for each object you want a rating for. The function, make_rating_model takes two parameters; the name of the model you want to rate, and a string that is used to generate the table name, to avoid naming conflicts.
To create a rating object you would import ratings in your models.py file and add the following:
class ArticleRating(ratings.make_rating_model('Article', 'mysite')): pass class ImageRating(ratings.make_rating_model('Image', 'mysite')): pass
Now if you syncdb you will get two completely independent models with essentially the same interface – which means you can write code that works equally well with model instances of either type.
This method doesn't quite replace generic foreign keys; if you don't know until runtime what model to reference, or if you require the objects to be in a single table, then you will still need generic foreign keys, but in my experience this is rarely the case.
Python developer programming tests
I recently administered a programming test to a number of applicants for a Python developer job at 2degreesnetwork.com. Since we now have a new developer (hi Gustavo!), I figured I would post the test and see what kind of response I get to them.
There are two parts to the test, neither are hugely difficult, but there is enough scope in the solutions to understand how the candidate approaches a problem.
In the first part of the test I asked the candidate to look at the following code and implement the thousands_with_commas function, which should take an integer and return a string representation of that integer with commas separating groups of three digits:
def thousands_with_commas(i): return str(i) if __name__ == '__main__': assert thousands_with_commas(1234) == '1,234' assert thousands_with_commas(123456789) == '123,456,789' assert thousands_with_commas(12) == '12'
I think there is a way of doing this with the standard library, and there is also an implementation in Django, but I was looking for a solution from scratch.
It worked quite well as an interview problem, because there is no one obvious solution and there are a few potential gotchas to tackle.
In the second part of the test, I asked the candidate to implement a function that uses a word list to return the anagrams of a given word.
I started them off with the following code:
def annograms(word): words = [w.rstrip() for w in open('WORD.LST')] raise NotImplementedError if __name__ == "__main__": print annograms("train") print '--' print annograms('drive') print '--' print annograms('python')
This part of the test gave a good indication of how much a candidate new about data structures and performance.
You can post code in the comments [code python] like this [/code].
Feel free to post your solutions in the comments, although I suspect I've seen pretty much all variations on possible solutions!
Django Desktop
I implemented a theme system for locidesktop.com and thought it only fitting that the first theme I made was one for Django.
I present you with the Django themed Loci Desktop!
Here it is, in embedded form – although you really need to click the above link to fully appreciate it.
Javascript Snippets
Since I've been hacking away with Javascript lately, I thought I'd share a few snippets that I have found invaluable.
Some of these snippets use JQuery, but could easily be modified to use plain JS or another toolkit.
Some of these snippets are likely available in other libraries and plugins, but I prefer not to introduce too many dependencies when working with Javascript. Better to keep the code lean – if possible!
When did I become the Javascript guy?
I have been busy working on locidesktop.com lately. One popular feature request from the beta testing was to use website favicons, so that links become more readily identifiable – which I have implemented after several late nights, and abusing my quad core.
I built a pipeline that downloads favicons, extracts PNGs which are then processed in to a 3D scene and rendered for missing resolutions (.ICO files can contain multiple resolutions). I've tweaked the way that the 3D icons are produced, and they are significantly better than my first attempt – although some do come out better than others.
The 3D icons are integrated in to locidesktop so that they are pulled in whenever you add a site to your desktop. At the moment I have about 20,000 of them, and I'll be adding more in the future.
The desktop editing interface has been polished considerably, and I think that it is pretty slick now, although there are still plenty of improvements to be made, especially in the area of context sensitive help.
If you really want a beta invite, let me know.
I've also created a test account so that I can demo the features of locidesktop.com without a login. The url is http://locidesktop.com/test/ to view the test desktop, and http://locidesktop.com/test/default/edit/ to play with desktop editing (but you won't be able to save).
As always, I welcome feedback…
Talented front-end developer job for Web 2.0 company in Oxford
The company I work for, 2Degrees, is looking for a front-end developer to join our team.
We need a CSS monkey with a good working knowledge of browser quirks and the ability to get even IE6 looking good (although you don't have to like it). It would help if you don't run away screaming from Javascript and can play well with the code monkeys.
More details are below. Email the address at the bottom of the job description, and mention this blog!
Turning website favicons in to 3D
The feedback I recieved from Reddit about locidesktop.com (my hobby project) was encouraging.
If you would like to join the beta program for locidesktop, please leave a comment below…
One of the comments pointed out that although there is a large choice of icons available, there isn't always a clear recognizable image for each site, and it would be nice if locidesktop would use ‘favicons’. I had considered using favicons previously, but rejected the idea because they are just 16x16 pixels in size, and I wanted to use large images for icons.
I didn't want blurry scaled icons either, and I may have abandoned the idea if a Reddit user hadn't pointed me at this which recommended embracing the pixelated look of favicons for use at desktop icons. I figured I could take this idea a step further and render 3D images from any given 16x16 image, using a combination of Python, Mako templates and Povray – the same combination of technologies I used for my (now defunct) 3D pie chart project.
My name is Will McGugan. I am an unabashed geek, an author, a hacker and a Python expert – amongst other things!
-
4 posts
-
2 posts
-
2 posts
-
1 post
-
6 posts
-
1 post
-
1 post
-
3 posts
-
11 posts
-
6 posts
-
4 posts
-
1 post
-
1 post
-
1 post
-
5 posts
-
5 posts
-
1 post
-
6 posts
-
1 post
-
9 posts
-
2 posts
-
4 posts
-
3 posts
-
14 posts
-
3 posts
-
1 post
-
7 posts
-
7 posts
-
16 posts
-
8 posts
-
2 posts
-
1 post