Friday, February 26, 2010

It's a unix system: Part 2 - Installing Django 1.1.1, Python 2.6.4 and MySQL 5.1.44

So this week I have mostly been configuring our VPS box. Although you'd think this would be an easy job, nothing in the IT world is ever easy.

Firstly getting back to grips with Unix took some time, getting used to the VI editor, chmod/chowd-ing, running shell and pearl scripts was a bit like attempting to remember leaving cert Irish. Unintuitive and slow.

So first I decided to put some server software onto the site. Cpanel cost 120 euro per year to install, a shit load of cash that didn't really need to be spent so I decided to battle with Webmin. Webmin uses port 10000 on the VPS and installed clean first time (from rpm). Trying to login though I kept getting 404s. I contacted the server admin and he said he can connect fine from his end. Queue a day or two of opening ports on routers, netstat-ing, opening ports on the firewall. I then tried to run Webmin through Apache, ambitious it turned out because Webmin was having none of it, the username/passwords weren't liked by the server and more time wasted. Eventually I sent an email of desperation to the server admin who discovered there was a firewall blocking the port his end. Nice. Once this was opened webmin was usable.

Now to the actual project part. I went with mod_wsgi to install Python as this is the faster and recommended plugin to get apache working with djgano/python. This installed fine, updated the httpd.conf to include the .so file. Few tweaks here and there. Python also installed clean as did Django.

Now to MySQLdb. This is a python MySQL plugin and causes problems everytime I try to install it. So I discovered a nicer way of doing it.

The first problem you encounter is setuptools missing. You could install setuptools into your python but I found it easier to edit the setup.py and enter

import distutils
from distutils.core import setup, Extension

This will add the libraries you need (this is for python 2.6 btw). You'll have to remove the setuptools reference.

Next the install will throw an error saying something about mysql_devel or mysql_config. This basically means you don't have the full MySQL install on your system. I made the mistake of just adding the client like you do for windows. Normally with MySQL I click the first download link and run the package but not so for unix.
It involves downloading the client, the server and the development package and running the rpms (rpm -i ) . Look down the download page and you'll see all the installations.

Once these are in rerun the install of MySQLdb and it'll work as it should.

Next is the problem of Apache and wsgi. The Django website will work fine for the scaffold code that goes around a wsgi installation. The biggest problem I had was with 403 errors appearing for all aliases and directories. Everything I tried didn't work and I've been to alot of sites on this. By some strange chance I got this to work and open my directories:
  
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny

This should get you up and running with Apache 2.2, Django 1.1.1, Python 2.6.4 and MySQL 5.1.44. My install was on a Linux RedHat CentOS server.

Sunday, February 21, 2010

Django db lists

Keep forgetting this one.

To get data from the database and convert into a list in Django

Entry.objects.values_list('id', flat=True).order_by('id')

iPad - why business should take a look

A few ideas" I had about the Pad".
Initially I had little hope for the latest $AAPL device but whenever Jobbs gets involved, change usually follows.
The mistake skeptics are going to make about it is that the device is neither a netbook or a phone. Comparing the devices is pointless, a netbook is a device for surfing the net, listening to music that sits on your desk or occasionally on your lap if you've "man on wire" balance abilities. An iPhone is a pocket device for calling, passing a few minutes on the tube and sending texts.

The iPad occupies a new user interface market, the example I was thinking of is its use as a survey tool. Say tesco have a promotion and want people to hand in fliers with their details. Traditionally you'd get a sheet of paper, fill it out and drop it into a box. Then someone picks up the sack, goes through each one, enters them into a computer. Old, slow and expensive.

The iPad in this case could be a survey app that could use the large screen area and touchscreen to enter in this information easily without requiring a desk for typing like a laptop would and having an interface that even grandmothers could read.

Another example is waiting rooms, why not have the magazine sized iPad to read? You could facilitate the filling out of doctors forms, removing manual entry and also allow users to read relevant articles (do magazines do online subscriptions?)

Irish Franchise Expo

So Brian and I hit the Irish Frachise Expo yesterday. A good indicator of a franchise value seems to be the eagerness of the franchiser to get you involved. Franchisers like O2 and Subway, the premier league of Irish franchisers (McDonalds is a shut shop), give out a few details, hand you a sparse flier and send you on your way.

Cartridge Green had a really good pitch. They run a franchise that reinjects ink into your cartridge for 25 euro. Not a bad deal really but I dunno is my future in injecting ink. They were really selling the "you have to love it", I wonder sometimes do people really love what they do that much. Like does a toilet cleaner have posters of toilet brushes and domestos on their wall? I'm not so sure but I never imagined myself doing work like that.



We did pick up the cards of some franchise "consultants". Although consultant does have as much positive connotations as "sex offender heroin dealer" they seem genuinely helpful (and free). There are 900 franchises in UK (according to our consultant), cartridge refills have probably 20 alone so he was saying to research until you cant research no more to get moving on it. Makes sense not to get caught up too early.


Pumping the stats
Statistically 90% of franchises succeed
80% of start-up businesses fail
However 100% of McDonalds will succeed, 95% of subways and PC worlds will succeed, lesser known franchises are down aroun 50% so it is something to bear in mind.

Thursday, February 18, 2010

It's a unix system

Living dinosaurs I can believe, little girls knowing UNIX? Yeah right

Wednesday, February 17, 2010

Zero Punctuation

Yeah, new zero punctuation

http://www.escapistmagazine.com/videos/view/zero-punctuation/1461-Mass-Effect-2

Server Hosting

Few problems with hosting. Shared hosting is proving to be a problem. For starters, no SSH access means we pretty much can't run/install anything other than CMS systems which is pretty rubbish.

We considered going to the cloud, as we're not exactly expecting mammoth numbers of hits. The cloud, the latest buzz, is the amazon EC2 affair. The future of web development. Even comes with a calculator.

http://calculator.s3.amazonaws.com/calc5.html

Trouble with the cloud is, like most things, strip away the silky velure and you realise that this is a whole pile of shite. For a prototype site you're looking at 500+ per year for a VPS (virtual private server). So great for those who want to upscale large sites and use resource "bursts". Crap for us.

So gonna use plain old VPS on our irish host at 18 euro per month. Functional, cheap, not so pretty but should work, like a wank sock.

Tuesday, February 16, 2010

Irelands inverted anus economy

Right, I ain't no fancy economist type but here's my take on the Irish economy.

The 100k lads. These people seem to occupy a range of positions, pharmacists, dentists, doctors, insurance. These people are the high rollers in our economy, high stakes straight out off college. Without any risk involved, just a college course, you seem to be entitled to the highest starting salary grades. Good for them right? We reward the safe job joes, the jobs we understand. My personal hope is that as volumes increase into this false economy, people are going to realise that having a piece of paper doesn't really entitle you to a whole pile in life.

Public service workers I know seem to generally be doing ok. Ok in the irish ecomony is a salary band > 50 k. So your teachers and nurses, generally benefitting from the safest jobs will generally be below this, circa 40k by their early 30s. Higher paid public servants will no doubt shoot well past this, a majority around the 60k mark and upwards. Not complaining here, those are hard enough jobs to get to and are regularly supported by union meddling and government quangos.

Social welfare equates to the nextlower bracket, we have a society which supports unemployment. Taking a job actually lowers your salary and cuts off benefits in alot of cases. On front line last night, an unemployed couple with 2 children were used as an example, having an equivalent salary of 39k. Not bad for doing nothing.

Now onto the lowest point of the bucket. Internationally competitive jobs, often export driven seem to signify the new low for the Irish economy. Engineers, designers, developers, anything that's export driven is a low income scenario. A job, that in a healthy economy, would normally be rewarding is instead pushed down the paid ladder. To the point that some of the worst paid in our economy are engineers. 40k is considered a decent salary (note this is 1k more than social welfare, add work related costs this disappears). So you're probably better off on the dole than working in an export driven industry. I recently encountered software developers working for 20k. We're looking at indian wages, soon enough we might have a chance to become an offshore hub if there wasn't a realistic economy across the water from us that has and will suck up our talent.

Worse still, is the fact that the self employed are entitled to nothing in this great state. For taking on risk and entrepeneurial ventures, the government removes any welfare if you fail and any entitlement to medical benefits. If you fail you'll also be prevented from ever being allowed to attempt to launch another venture again. I think it makes sense to add an "if you fail - you will face casturation" clause to the constitution.

So I term Ireland, the inverted anus economy. It prevents exports from flourishing and promotes the retention of anti-competitive strategies. Holding onto the shit and acting exactly opposite as to how a healthy economy works.

So as a mantra for living here, I like to think the clever screw the system, reap the benefits, work as many nixers as you can, get your medical card, milk every entitlement. The sooner the state (or IMF) realises that EVERYTHING IS BROKEN, the quicker we can start from scratch at building somewhere worth living and working for.

Thursday, February 11, 2010

MySQLdb import setuptools registry key blah

For my nth time reinstalling python and setting up MySQL on a windows machine, i'm back to the same list of errors

ImportError: No module named setuptools

I go find setup tools and install this. Next:

File "setup.py", line 15, in
metadata, options = get_config()
File "C:\Software\MySQL-python-1.2.3c1\setup_windows.py", line 7, in get_confi
g
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_ke
y'])
WindowsError: [Error 2] The system cannot find the file specified

Gotta love these errors. Completely unintuitive for a relatively tiny and essential package.

The solution???

Give up trying to use the latest release, maybe it's optimised for linux anoraks and use:

http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe

This installer will sort out everything

Wednesday, February 10, 2010

Filtering list in Django

Right so .filter is the way to get data from a query set. How do you go about filtering a set based on on a different set?

For SQL heads this is usually done by WHERE ID IN () or WHERE ID CONTAINS()

What you need to do in Django is convert the () part into a list and filter as normal

random_questions = All_Questions.objects.filter(pk__in=list(ordered_questions.values_list('id', flat=True))).order_by('?')

Flat = true implies the results are returned efficiently [1,2,3] as opposed to [(1,),(2,),(3,)]

Tuesday, February 9, 2010

Extending Django user model

Right so using the nifty Django user model is easy but how do i create a foreign key reference?

First use:
from django.contrib.auth.models import User

This gives access to the user model. Then just use the user as you would a normal foreign key reference
user_fk = models.ForeignKey(User)

Sunday, February 7, 2010

Back from Val Thorens

Well Ski trip is done for another year, board survived intact this year and no bones broken which is always a good sign.

Will be moving this blog subject more to tech things i'm working on, first should be the use of the twitter Geo-location API.