Archive

Archive for 2007

got Mac

September 3rd, 2007

I finally did something I should have done a long time ago and bought a macBook. It’s wonderful – like Linux only hardware works; like Windows only it doesn’t look like crap…and hardware works.A lot of thing on Windows I had started to take for granted: “If I want to do this, I must first do that” or “This works when that is already running” but OSX seems to take care of a lot of this stuff under the bonnet, so to speak.

The Mac came with a plethora of software for it’s internal peripherals and features – web browsing, photo software, iTunes, quicktime – pretty much what you’d expect. Further to this the apple development tools is a free package adding a good gigabyte of extra tools, SDKs, documentation and utilities. Add to that Mactex and Emacs and you’ve pretty much got a complete development station.Package management is dead easy – in most cases simply dragging the application into the ‘applications’ directory.

The User Interface is very smooth without being obnoxious. I for one am very fond of seeing windows slide off the screen and back in… my brain seems to comprehend window management when bits and pieces move around for it.If I have but one complaint, it’s that I seem to require almost an entire installation of Gnome just to get Gimp up and running: It may be time to explore the image editing market again.

[edit] It turns out there is now a rather nice Gimp package for OS X.

Computers, Development, Geek, fun, life , , , ,

Python: Fun with Threads

May 3rd, 2007

Most people will agree that threads are an important part of most useful software systems. They allow the computer to go off and work on something while the user continues to enjoy interaction with the rest of the system – In fact most GUI applications are a prime example of threading – The interface is running separate from the core of the application to ensure that if the application dies behind the scenes it doesn’t necessarily take the rest of the computer with it. (However some win32 applications would have us believe otherwise)

The problem with constructing threads, however, is usually the housekeeping that needs to go into the background. We need to think about the data interactions and decide what data needs to be encapsulated in mutual exclusive surroundings for safety. Then we need to design the thread(s) that will modify this data.

Suppose, however, that you just want to despatch very simple threads that will run a single function. Why bother doing that tedious work? Well, after a quick look at how standard python handles threading I thought of a neat way that one might create a generic thread handler to request functions to be done neatly in the background. This code was written with a vanilla installation of Python 2.4 on Windows XP. I don’t know enough about Python to write ‘OS specific’ code so it should work on most machines.
ALSO: Since python is a live interpreter all this code can simply be typed into the python shell.

The first step is to import the python threading library

import threading

Now Here’s a simple function:

def factorial( n ):
if n == 0:
return 1
else:
return n * factorial(n-1)

Very simply takes a number and returns the factorial. I realise that it’s not the most practical way to implement factorial but it’ll do for a demo. What I’m going to do now is write a thread class making use of pythons groovy function pointers:

class AsyncFunc(threading.Thread):
def __init__(self, func, n):
threading.Thread.__init__(self)
self.function, self.arg = func, n
def run(self):
self.result = self.function(self.arg)
print “result: “, self.result

Pay attention to the parameters in the class header – the class extends threading.Thread. This means that we want to call the constructor of the supserclass and this is done in the first line of __init__. (__init__ is just python’s fun way of implementing constructors). We create an instance of AsyncFunc giving it a function and an argument (I have only shown a demo for single argument functions – things like square, factorial, fibbonacci.) and these are stored as members in the class.

The run method is the sequence of execution that will happen when the process scheduler tells this class it can start working.In this case all we want to do is run our function with the argument given. This is a really, really, truly cool feature of python that I love – the self.function member is actually a link to the factorial function which we passed in as a parameter – you can’t do this in Java!!

At the end of run I’ve just told it to print the result to let us know it’s finished – in a real world scenario we may also pass a buffer address to the function so that we can get access to the result from our main process.

We are now ready to start using our threaded system and it’s as simple as this. first declare an instance of an AsyncFunc:

bgFactorial = AsyncFunc(factorial, 5)

and then pass it to the process scheduler:

bgFactorial.start()

In no time at all the result will be returned – but rest assured it happened in another thread. You can redefine your AsyncFunc with larger values and see that it takes longer but doesn’t disrupt your work.

Just for a laugh I added the following loop scenario – a word of caution though, you may either spawn more threads than the python system can comfortably handle, or you may exceed the maximum recursion depth (because the factorial definition is not great)

for i in range(1000):
temp = AsyncFunc(factorial, i)
temp.start()

I managed to grind my python session to a halt, but it’s all a bit of fun anyway.

Hopefully this has been a little insightful or interesting. I was trying to capture something similar to the Microthreading that can be used in Stackless python

Computers, Development, Geek, fun , ,

The Ulsterbus Saga Pt.1

March 27th, 2007

As of Monday 26th March Ulsterbus raised their prices yet again. However, I figured from experience that this information would not yet be apparent on Translink’s website. I was surprised to find that indeed they have already updated their site with the new ticket consessions – however they are still advertising the student return ticStudent Return Ticketket at the old prices.

Seeing an opportunity I decided that I would only pay £4, no matter how far I had to fight it!

The bus driver was the first obstacle. I handed him the £4 and said “Student return to Belfast, please.” He punched it in – £4.10 came up. Undaunted I told him that the translink website was advertising the student return at £4. He replied “Well, this machine says £4.10.” A slight argument ensued and his finishing move was to tell me that either I pay £4.10 or I stay in Ballyclare. The offer to take it up with an inspector at the depot was presented.

On arriving at the depot I tell the driver that I will only be a minute. I approached the office and stated my case. The inspector responds that maybe the website just hasn’t been update yet and asks when I checked it. Calmly, I inform him that it was only about 20 minutes ago; that the ticket prices had been updated on the website, and finally that the student return was still being advertised at £4. He spent that next 10 minutes on the phone to customer services.

I was next told that since the Ballyclare depot has no internet access my claim cannot be backed up, a rather lame counterpoint I thought and the inspector made no false inpression that he was in any way impressed by my quest for a 10p refund on my ticket.

This is the situation at the moment: If I can produce a printout of their website showing this falsely presented information then Ulsterbus will gladly write me a cheque for 10 pence.

I just want to say at this point that I’m not doing this for the money, but more for the reason that Ulsterbus will gladly defend their right to present inaccurate information and expect the consumers to put up with it.

fun, life , ,

Good Article on Professional Development

March 23rd, 2007

Andres’ thoughts – Top ten things ten years of professional software development has taught me

This article really rings true, especially if you end up working at a large company. I know when I worked at Microsoft being able to talk to the other developers and managers was much more important than knowing every last thing about C# or C++.

Computers, Development ,

More CG Please!

March 15th, 2007

Wow… It’s been what? 3 months since the last CG Film was released. Some of us may have been hoping that the novelty had finally wore off – That stories could once again be told through the most suitable medium rather than being wrapped into that template applied to animation.

Fear not however as some unknown company (that’s right.. apparently no-one is owning up to this as of yet) has created just the movie to capture our imaginations and transport us into a childhood land of fantasy.

The movie? Well – it’s The Reef released on the 9th March in the UK.

The Reef Poster

The story explores the unfamiliar waters of a child who is separated from his parents and makes a new life on a reef – it’s almost an original plot already. Some of the characters you may not have recognised before – There’s a Pelican, at least one turtle, and a nasty shark who appears to be sneaking up on our heroes with a friendly smile on his face… Wait a minute. I’m sure I’ve seen that smile before…
Finding Nemo Poster

Of course I have, because Pixar already released this movie 4 years ago. How could I forget.

“Hey… unknown company! Didn’t you realise we moved onto vehicles this year? Hurry up and give us more cars!”

Come to think of it, Dreamworks have not yet released their own movie about vehicles. It seems odd for a company who’s current practice seems to be closely imitating Pixar but with more celebrity voiceovers.

(After a little more scouting I have discovered that the company responsible for this is ‘Digiart,’ however I intend to leave the post as is because ‘unknown company’ has better rhythm)

Computers, Graphics, movies , , ,

Facial Recognition

February 26th, 2007

The seems to be a new bebo toy which has definitely gone to the top my my list of “Things to waste a bit of time of the net”

MyHeritage.com’s celebrity facial recognition is a lot of fun to play with and I am well pleased to see that I have a 75% similarity to Drew Carey. Undoubtedly the highlight of my week! :-)

See my results at Bebo

Graphics, fun, life , ,

Modular Karma

February 2nd, 2007

At the start of the week after experiencing what promised to be two really good subjects: Formal Methods, which deals with rigorously specifying software behaviour through mathematical proof; and Artifical Intelligence, which has so far dealt with what we already know about propositional and predicate logic; I have felt as though these course are really going to compliment each other with regards to the application of theory.

I naively thought at this point that I was in for a very academic semester, however, I underestimated the karmic balance at the heart of every timetable, for the other course I enrolled in was High Performance Computing. A deceptively uninteresting module.

I have come to accept that is is unlikely to score three very good course in one semester and as I look back over the past 3 year I know that I can name one module per term that lowered the standards for attendance on my part.

I maintain, despite this, that I will aspire to attend lectures this term, I will complete assignments in a timely fashion and I will enjoy the overall semester.

Computers, University

Mornings

February 1st, 2007
0645 I wake up with the intention of getting the 8:30 bus into Belfast
0647 Stare at ceiling
0705 Decide to get whichever bus is after the 8:30 bus. It turns out I don’t want to arrive into Town only to waste a couple of hours before lectures
0720 Roll out of bed and shuffle over to the computer. I need to check the bus timetables online to see what time the next bus is at
0725 It’s at 9:45 and that will get me into Belfast at about 10:30. Not too early, not too late.
0730 I open my Webcomics bookmarks to give me something to read for a few minutes. There’s nothing new so I content myself with flicking back through old XKCD.com comics and the blag
0830 Still reading xkcd. I suddenly realise an hour has passed and I have to hurriedly get ready and leave the house in time for the bus.
0835 I proceed to have my breakfast, have a shower, get washed, dressed, pack the stuff I need and reach the bus in time. There was never really that much pressure.

This applies to most mornings, I’m lucky enough this semester to not have any lectures before twelve o’clock, which gives me the freedom to choose; will I appear in the lab early, enthusiastic and ready to take on the day? or will I sleep in, take time over breakfast and casually arrive just in time?

Not really a choice at all.

powered by performancing firefox

University, life , ,

Exams done

January 22nd, 2007

Three exams for last semester: concurrent programming, Programming Language Implementation and Ecomics, Management and Entrepreneurship.

Well, I mentioned before about my aversion to the economics module – in fact I don’t feel the exam went all that bad. Looking back over the past three weeks the exams in general went fairly well (as far as I can tell) – I don’t believe I screwed anything up at any rate :-)

Now I have a solid week of unwinding before the next term, time to warm up the Wii.

University

Happy New Year

January 4th, 2007

The obligatory Happy new year post for 2007, only a few days late ^_^;

Well, I hope everyone had a nice break from work for however long or short it was… all two of you.

Technically I’m still off for yet another month, however as exams start to loom closer it feels less and less like a holiday and more a period of rapid reading and trying to force my mind to remember stuff it really doesn’t want to. I still can’t imagine why I would ever want to know about marketing or economics; at this point neither topic is something that dwells in the forefront of my mind. I’m sure they are great subjects, and if I ever feel like moving into that area in the future I could research them myself. Forcing students to take on an unrelated topic like this, whilst also balancing the work for the important modules is something Queen’s excels in.

Anyway, I’ll try to avoid the long austere road of Queen’s and stick to the lighter topic. Once again, I hope the new year was extremely bearable for everyone reading.

University, life