Posts Tagged ‘Python

04
Dec

Pinax

Thanks to listening to the #ubuntu-uk PodCast - I came across this little gem.

Pinax Project

It’s a collection of reusable django apps - all designed to be reusable - together.

What this means?

This project needed a critical mass to get it off the ground.  Basically the way things are referenced across all the apps need to be the same.  There’s no point having two reusable apps.. if they both require different ways of interfacing with the same object.  They break if one has ‘name’ as being fullname, and ther other requires name to have two separate name fields (for firstname and lastname).  You’ve then got to write a way of getting around this problem, which just increases as more features were added.

Well, the neat guys over @ pinax have started up a project on creating re-usalble apps that sing of the same hymnsheet - and they look awesome.  Having watched a presentation on youtube, the following phrase (quoted) stood out for me:

“If you want a man to build a boat, do not send him out for wood and nails, but teach him to yearn for the wide and endless sea.” -Antoine St Exupery

It’s really accurate for these kind of projects - writing reusable apps off some other guys prescribed instructions doesn’t fill the heart with glee - but seeing what can be achieved by doing this makes you want to contribute.

So Cloud27 was born - it’s a social network, but made up of the componenets developed on pinax - meaning you get to play with what you’re about to download an integrate into your own project.

It looks really good, and there’s a project I’ve been meaning to do which has been yearning out for a kickstart - I think this may have just done it!

24
Oct

Django League Table

I’m trying to write a league table for some sport results using django.  At the moment my model looks pretty basic:

class Scores(models.Model):
    matchnum = models.AutoField(primary_key=True)
    homeuser = models.ForeignKey(User, related_name="hmuser")
    hometeam = models.ForeignKey('teams', related_name="hmteam")
    homescore = models.IntegerField()
    wayuser = models.ForeignKey(User)
    awayteam = models.ForeignKey('teams')
    awayscore = models.IntegerField()
    pub_date = models.DateTimeField(auto_now_add=True, editable=False)
    def __unicode__(self):
        id = str(self.matchnum)
        return id
    class Meta:
        verbose_name_plural="Scores"

class Teams(models.Model):
    teamname = models.CharField(max_length=40)
    def __unicode__(self):
        return self.teamname
    class Meta:
        verbose_name_plural = "Teams"

However, with the information in this simple model - I should be able to generate a league table, with the following fields:

Team Played # Won Drawn Lost Goals For Goals Against Goal Difference Points

So how to put this into a Django App? Well I need some advice, as my original method was to edit the save() function of the model to input fields into a new model - however, I should be editing things at the form level. I’d also like a ‘generate league’ method, rather than a method where a league is generated at the end of each score addition. The main advantages of this approach is that I can:

  • Generate the League from existing score data.
  • Future Users can generate the League from their data.
  • Leagues can be generated at the end of each ‘gameweek’ - rather than just at the end of each game.

Django is a fantastic python framework that I’m immediately getting to grips with - but as this kind of application (simple as it is) - is one that’s scalable and may be useful to many other users.. I want to get it right from the start.

I’ll be tagging the posts with ‘djangoleague’ if you want to keep up with development - and if anyone wants to use the project/help me out with it - please post in the comments and I’ll get back to you.

25
Sep

My programming career begins (with bugfixing).

It’s taken me a while, but just over 12 months learning the basics of programming, I’m finally contributing and commiting code to my company’s SVN repo.

One of the things I like about programming, is that it seems to suit me.  Having not done any programming at all before 12 months ago, jumping in at the deep end and going into a career that requires it wasn’t an easy step to take.  However, I’ve had some good guidance from my colleagues - in that I’ve not settled upon a single language.  I wouldn’t say I know any language well, but I’m reading and understanding code better than I’ve done before.

The hardest part for me, is looking at a problem and seeing my own solution - rather than the solution that’s coded infront of me.  Once I’ve understood the train of though of the original programmer, it’s alot easier.. however, at the start I was failing to do that.

At the moment I’m happy making modifications and bugfixes to programs.  It’s simply enough stuff, where auditing and testing the problem takes by far the majority of the time.  However, I’m understanding things better - and feel like I’m finally making some decent progress.

I know it’s possible to contribute to open source in other ways than just coding (I’ve been doing that for the last few years) - but now I’m coding I hope to submit code to the projects I like.  It’s been my aim for a while.  I’ve set up my bzr repo, but most of my code at the moment I’d hope to submit as patches to other projects.  Who knows what the future will hold.

07
Sep

Jumping in.. Django+Facebook

It was easier than I thought to write my first django application, especially as I was using solely the administration interface as the front end.  I didn’t need to touch the view.py or forms.py to get things working the way they should.  In my opinion (and my clients) that’s a fantastic result.

So now, rather than let my skillset rest like that, I’ve decided to become a little more adventurous.  I’m in the design stage of a django+facebook application.  I’m wary about linking myself directly to facebook, so the application will have a ‘core’ element (where all the logic will sit) and a ‘web’ and ‘fb’ app, for handling the two interfaces, respectively.

This wonderful solution came from a guy called Will Larson, who blogged here.  It’s a great little article, on how to easily access the facebook api, using pyfacebook - but without the pyfacebook middleware.  Although there may not be technical benefit in doing this, from an educational perspective I can immediately see how he accesses the API and how I can quite easily start to manipulate it myself, using FQL (Facebook Query Language).

I’m a little apprehensive, as I want to get the design right.  I’m really looking forward to jumping into this project for a couple of hours a day, and seeing it evolve.  I’m going to be putting all the code up on my bzr repo (football) - but I hope that in the not-so-distant future someone will poke me and ask to link it to Launchpad, so they can help too.  However, this is a learning project for me, so I hope to do most of it myself, and understand all of it.  I’ll probably put a clause in the license that unless your code is commented enough for me to understand it.. you’re-outta-here.  Reckon that’ll work?

05
Sep

Bazaar Repo Open

Now I’ve got the bug for a bit of coding (pardon the expression) - I thought it best to set up my own publically viewable bzr repo.  Launchpad is a great platform for collaboration, but I feel like some of the stuff I’m working on doesn’t belong on Launchpad.  The projects I’m planning to work on have a shelf life of about a week, so I don’t want to clutter up Launchpad until I know I have an applications that others will want to collaborate on.  With bzr, when that time comes, it’ll be easy to do.

So today, I spent a whole 10 minutes (I was amazed at how easy it was) setting up my bzr branch..  it’s up at http://bzr.zrmt.com (using Launchpad’s very same loggerhead browser).

If you want to check out the code, or branch it.  I’d recommend just dropping me an email for now.. I’ll link it to Launchpad so that we can all contribute the code to the same codebase.. after all.. that’s what it’s all about.

03
Sep

Django.. I finally made the jump.

After working on my own php + mysql system for Purchase Order Generation, I realised that in order to get the code ‘right’ - I’d need to rewrite it multiple times in order to utilies the Object Orientated advantages.  After rewriting a single page about three times, each time improving my code and making it more scalable, I felt that I was wasting my time.. as each time I finished it, I’d improved myself sufficiently to see a better way of doing things. How annoying.

For the last few months, I’ve been looking to Django.. not for this project - but as something to be used for designing some private websites.  It looked neat, used python (and language that I find quite intuitive) and a few guys from SBLUG used it.. so I knew I had some people to go to for support.  However, my first few attempts at the tutorial involved me really immersing myself in the framework.. and having not used a framework before, I really wanted to undestand the entire structure of what I was doing.

Finally, I was able to designate a portion of my time to this new Django project.  Since my php+mysql project needed rewriting, I thought Django would be a good way to kickstart that.. and I wasn’t wrong.  I don’t think I’d have had much success had this been my first exposure to Django, but I managed to get things ticking over quite smoothly.  I went through creating my models and populating the database with ease.  There were a couple of problems that I had to get the guys in #django, and the lovely Danux from SBLUG to help me with.

Despite all that, what had taken me a few rewrites to do in php+mysql was running great in Django.  I’d even managed to set things up so that the functonality I needed could be provided entirely thorough the admininstration interface.  Coupled with the brilliant contributed permissions and user/group modules - I was able to set everything up exactly how I wanted.. with much more functionality that I could have hoped to acheive using my previous approach.

So, God Bless Django.. and I hope that this is the beginning of a fantastic partnership.

 

all my code is available on Launchpad.. www.launchpad.net/~andylockran

04
Aug

Time to switch to Django

Over the last week, I’ve been playing with http://po.zrmt.com.

It scratches a very small itch for my uncles company - and is going to be quietly expanded to manage more and more things for him. However, the current state of the program means that it’ll work well enough ‘as is’ - but I really need a framework for developing the ideas further.

I’m already learning and seeing better ways of doing what I’ve already done. I guess it’s just the learning process kicking in… but there are lots of things that I’m not entirely happy with. Feel free to take a look at the code :) I guess it’s time to switch to Django.

I’ve tried a couple of times to switch to Django.. but I never really managed to get off the ground. However, I think this project required that I use a framework, and will also help me make the code scalable. With the potential for this same project to be used by at least a handful of companies around Birmingham.. it’s not something I should turn my nose up at (although it’s unlikely to make me a millionaire).

I’ve always used php before for my web-coding. It’s one of those things that just seemed nice at home to me; sitting embedded in HTML. I basically used it as variables for HTML processing.. without a loop or an array in sight! I can see now where I can actually begin to use the programming to make things simpler.. not more complicated. Ooh it’s exciting.

The other thing is that it means applications I create are more likely to be used by other people. Django applications (as far as I understand it) are a collection of lots of small apps based around a solid framework. It means there’s probably going to be less work for me, and less work for other people. The comments that I made in “Using the Long Tail” are massively relevant. The more applications there are around a common base - the more random and unique the connection between two applcations.

So soon I shall be starting my move to Django. Hopefully there’ll be a few readers that’ll follow my trials and tribulations (and also help me with any potential problems). The first thing I need to do is install it on a remote ubuntu server.. if there are any gotchas with doing that - please let me know.

12
Jun

David Davis - The Digital Debate

Too many D’s for my liking… but a fantastic marketing point.

After David Davis resigned from the Commons today, the speech he gave focused on where technology and policy collide.

We will have, shortly, the most intrusive identity card system in the world, a CCTV camera for every 14 citizens, a DNA database bigger than any dictator should have with thousands of innocent children and millions of innocent citizens on it.

We witness and assault on jury trial - that bulwark against bad law and its arbitrary abuse by the state, short cuts to our justice system will make our system neither firm nor fair and the creation of a database state opening up our private lives to the prying eyes of official snoopers and exposing our personal data to careless civil servants and criminal hackers.

It’s definately time for the debate to happen.  Just because we can do things with technology doesn’t mean we should.

16
May

OLPC - Is advocacy a profitable business model?

Having just read Rory Cellan-Jones article on the BBC News Website about the OLPC choosing to use the Windows XP operating system, I felt it sensible to put forward the reasons why I think it may/may not be a bad thing, and who’s going to benefit from the deal.

Education versus Training

Unfortunately, I think the UK IT Education System passed under this bridge so far up river, that it would require getting out of the river, and a hard trek upstream to ever get back to fixing the problem.  Since 1997 (the year I started secondary school, and the year the Labour government came into power), there has been a worrying trend toward using the education system as a training system.  I enjoyed my first couple of years IT lessons - we played with things like Logo - and used some very simple database software (key-plus?) to understand the power of databases.  We also used MS Excel to enter data into spreadsheets, and learn some basic formulae - as well as being told how to write the same formulae on the Lotus 1-2-3 spreadsheet software I had at home.

The difference that occurred in Year 9 (when RM ‘upgraded’ the IT suite at school) - was that we were now using MS Office.  Sure, we’d had Word and Excel on the PCs before, and I guess the financial costs of upgrading to Office rather than having the two separately are minimal, especially once you take into account the “educational discount” that schools are entitled to from Microsoft.

This meant that everything we did was MS based.  The simple database has gone, we were using MS Access.  In essence, IT lessons involved being trained in how to use basic productivity tools for our future office careers; which, in my opinion, is not something that the Education System should pay for.  I’d prefer to see people have an understanding of the difference between the ‘web’ and ‘email’;  the difference between what a Spreadsheet can accomplish in comparison with a Database; and hopefully a way for people to be taught on looking after their data, online and offline.
Advocacy as a Business Model

I recently watched a lecture given by Nicolas Negroponte in 1984.  In it he discussed his ideas for the future of Computer Interfaces.  It was an interesting talk, as he spoke about experiments he was doing in some African Countries on UI design.  However, he also noted that he’d done a dry-run of these experiments in New York previous to heading out to the African Continent.

In the school in New York, there was a child of around 14.  He didn’t know how to read and was seen as needing Special Needs treatment.  However, he was simply left to fend for himself in the IT rooms.  One of the days, a local council worker came to visit the school, and happened to notice this child in the library, so asked him what he was doing.  He showed him what he’d created on the screen using the ‘LOGO’ program.  The council visitor was suitably impressed, and asked him if he could do a little variation on his work.  Rather than simply say ‘no - I don’t know how,’ the child reached for the manual, worked out how to do it - and did it - clearly pleasing the visitor.

The visitor then went to the Principle’s Office (his reason for attending the school in the first place) and happened to mention the child.  The principle was certain that the visitor was the victim of some kind of ’set-up,’ therefore took the visitor down himself to see the child demo his abilities.  Lo and behold the child was able to do a further variation on his work by looking through the manual.

When asked why the child could read the manual, yet could not read the books provided to him in class, his answer was akin to the following: “What the teachers give me in class is boring, and I don’t get anything out of it.  However, when I’m on the computer and working, I can see the results of my efforts straight away and get rewarded for them.”

OLPC - Sugar UI

The Sugar UI for the OLPC project, for me, was a symbol of the ‘LOGO’ program for this child.  Someone that the teachers has written off as a massive underachiever had been able to produce ingenuity and learning independently - given the resources to do it.  Encouragement wasn’t necessary, as the learning process is something organic to the human mind.

The Sugar UI isn’t about being Free and Open Source (thus cheap) - it’s about so much more than that.  However, it’s also not the be-all and end-all of the OLPC project.  There are thousands of Open Source applications that can run on top of Windows XP that the OLPC users will be able to access.  It will also open up their opportunities for developing for FLOSS software on Windows Desktops - and thus be able to access the Windows Market in developed countries.

Why did OLPC do the deal?

For those of you that have been following OLPC, you’ll know that the ‘Intel Classmate’ has played some underhand tactics in order to get their processor on the OLPC - and then pulled out once they’d hijacked the relationships that OLPC had with important African leaders.  There’s so much corruption in Africa, that XP was probably an (unofficial/off the record) requirement.  Sometimes you’ve got to get in bed with the bad guys to help the small guys.

Where does this leave OLPC in the future?

OLPC ‘Ltd.’ will always be the pioneers to the concept of OLPC.  The aim is a noble one, yet in what is essentially a commercial market - pure advocacy fell to the power of multi-national marketing.  However, it has opened up a new market in the developed countries too - of Ultra Mobile Personal Computers - many of which run Free / Open Source Software.  This can only be a good thing in the long run, with more and more people using FLOSS and seeing the benefits.  Coupled with the coming-of-age of Ubuntu, and the fantastic marketing effort that’s coming with that, Nicolas Negroponte can be confident that where his company may have compromised - his idea is still being pushed by those supporting him.

18
Apr

Who reads blogs?

I was having a discussion with a few mates in the pub this evening about my blogging ‘antics.’ They’ve berated me for blogging before, but as it’s becoming more and more widespread I can see them getting more interested in my motivations for ‘blogging.’

One of the friends commented that it was purely the fact that he knew me that made the blog interesting. For someone that didn’t know me, the blog would be pretty dull and of no consequence. At this point, another chipped in saying - “Only bloggers read blogs.” Is this true? I don’t know, but I don’t think so.

My motivation for starting the blog was that it was a place where I could share my technical insights. Not profound insights such as the advent of structural-object-abstract programming methods that I’ve just decided are going to be the Web 3.0 - but short howto’s and the like, and to publish a few ‘Gotchas’ - problems that have few symptoms and a nice easy solution - but take hours of work to solve. I blog advice - There’s nothing quite comparable experience.

(un)Fortunately, which ever way you personally look at it - my blogging has branched out to cover all sorts of things. From the time when some guy smashed the window of my car, to re-living and walking through my car accident in 1999, to a short article on why to avoid Red Hat’s bundled openLDAP implementation because it’s crap.

I think it’s an interesting concept, for non-bloggers and bloggers alike. Who reads blogs? If you have a regular commentator on your blog, do you add him to your blogroll as a thanks for lifting your self-esteem by having him visit your blog? Do you think you have a regular readership, or just random visitors popping in and out after being directed from Google?

I don’t think it’s a negative thing that bloggers read blogs. It’s great. From the attendance at the spontaneous meet-up last Friday, it’s clear to me that there’s a nice little community of bloggers in Birmingham. However, this is a meeting of a cross-section of the readership who it’s worth meeting face-to-face in order to better your own blog.

Is blogging journalism? Is it art? Is it a cry for help from some pathetic moron wanting to share his story with the world? Is it ‘new media’? Does it matter?

I blog tech because I think some people read it and it helps them - and also as an easy reference for me. I blog ‘about me’ as a way to vent some thoughts and get some feedback from an audience who I think would be interested. This audience is dynamic, therefore I categorise my posts different to respect that.

When doing my Psychology degree, one of the things we covered was ‘online personalities and freedom of information.’ This blog is in the public domain. If it were a diary, having it leaked would immediately bring headlines of ’scandal and gossip.’ My blog is sort of a base for my online identity. ‘andylockran’ lives here. I happen to pop up on a mailing list or a forum or IRC and you want to know more about me. Much of it is here. It’s a bit like ‘CV 2.0.’ The web is my field - if I don’t market myself well on the web, how the hell can I expect anyone to be able to trust me to market their products on the web?

The best thing about it for me is the feedback, both positive and negative. Setting up a blog exposes you to both - and it gives you the opportunity to have a voice.