File age in python

For file cache algorithms it would be useful to have a function that gives you a simple True/False answer to the question, is this an old file? The following provides just that.

import os
from datetime import datetime
from datetime import timedelta

MAX_AGE = timedelta(minutes=5)
def is_old_file(filename):
    current_time = datetime.now()
    file_time = datetime.fromtimestamp(os.stat(filename).st_atime)
    return current_time < file_time or (current_time - file_time) > MAX_AGE
Posted in Programming | Tagged | Leave a comment

Terminal on Lion

Open up terminal. Click the fullscreen button (top right) and it takes up all screen space. It’s like a programmers wet dream :-) .

Posted in Programming | Leave a comment

Seriously!!!!

It’s a chopping board. It’s so that you don’t mix up your meat and veg!…   He calls it “The Big Chopper”.

Frankly, seeing this at the ideal home show was a surreal experience. And, begs the question, where does he store it?

Posted in Lifestyle | Tagged | Leave a comment

Barcamp

I’m off to Barcamp at the end of this month. So, what do I have to talk about? Business process? New languages and environments? Trends in the set top box market? Hmm.

Posted in Lifestyle | Leave a comment

Fun. No, really!

Posted on by Michael | Leave a comment

Chinese version of Countdown

May I have a vowel please.

Another vowel.

Can I have a vowel please.

I think I’ll have another vowel.

Hmm, vowel please.

….

(you get the idea)

Posted in Observations | Tagged , | Leave a comment

Vala Generics

Vala supports a limited form of generics. It’s a shame, coming from a Java background not to see the thorough implementation that I am used to. Vala coming from a C# background might have inherited it’s form of generics, but that sadly was not possible, and with good reason. Vala maps onto an existing type system, whereas C# generics was a revolution in the underlying type system.

What’s the point? Well, it’s easy to break. Not that you should be trying, mind, but you should be aware of some gotchas in the polymorphism.

class AContainer {
    string value;
}

class A1Container : AContainer {
    string value1;
}

class A2Container : AContainer {
    string value2;
}

void add_something(List<AContainer> list) {
    list.add(new A1Container());
}

void main() {
    add_something(new List<AContainer>());  // Good
    add_something(new List<A1Container>()); // Good
    add_something(new List<A2Container>()); // Bad!
}

I have typed this from memory, so please forgive the odd mistake, but it gets the idea across. It is perfectly possible to, within the rules of the language, put the wrong type of object into the container.

If some other peice of code that depends on a List<A1Container> having exactly the expected types, with the expected visible fields, is executed, we can very easily corrupt memory and/or crash the program.

Like I say, this is just something to look out for. After all, we’re real programmers aren’t we!

Posted in Programming | Tagged , | Leave a comment

A2DP on Ubuntu 11.04

I have purchased a lovely new Bluetooth stereo headset for me, well, everything. It works so well with the iPhone, no problem with my MacBook, and with the Ubuntu Linux laptop?..   It works, but I couldn’t find the advanced profile. For others like me, here’s how to find it.

  • Click the Bluetooth icon on your task bar and select “Set up new device”. Put your headset into discovery mode, in my case by pressing and holding the on button for a while.
  • Select the device from the list and continue.
  • Click the Bluetooth icon on your task bar, and look for your device name under the menu. It should appear as a sub menu, with Connect/Disconnect/Open Sound Preferences. Select the latter.
  • In the sound preferences dialog click Hardware, and select the device. At the bottom of this window should be a drop down box called “Profile:”. Here you can select “High Fidelity Playback (A2DP)”.
  • Click the Output tab, and make sure your device is checked.

Well, in theory that’s job done! :)

Posted in Equipment | Tagged , , | 5 Comments

SEO and IE

I am trying my hand at SEO (Search Engine Optimization) at the moment on my wifes site. It goes, averagely.

One technique is to restrict access to excessively verbose parts of your site. Anything that is basically generated, and where the number of pages can be huge, might look to a search engine like an attempt to spam their indexes. Well, actually, her site had a robots.txt file to prevent access to those pages. Guess which major search engine ignores that!..   Oh well.

Next attempt is to add “rel=’nofollow’” to every href into those generated pages. One quick bit of research later, I discover that our favourite major search engine will follow those links anyway. It may or may not index, but will follow.

Moving on to the <meta name=”robots” content=”noindex”/> header tag for every generated page. This should do the trick, however search engine no. 1 has one last irritating trick up its sleeve. It has a long memory. If it has previously indexed a page, all these measures will not make it forget the page. So….

Last trick, rename all the generated pages, so that the old links generate 404 and major search engines forget them!.

I’ll report back later. Wish me luck.

Posted in web | Tagged , , | Leave a comment

Running hurts

I’m 37 and generally not fit. Next to me is a field that has a diameter of 1.7 miles. So, recently I decided to run around it! Being of little experience, I put on the cheapest trainers I could buy, and tortured my self every other day around that field. But after two weeks, my shins started to hurt.

It turns out that this is a common complaint amongst runners, especially inexperienced ones. Shin splints are tiny fractures (so I hear) in the bone, and frankly, I don’t like the sound of that.

Posted in Lifestyle | Tagged , | Leave a comment