Tuesday, 30 June 2009

Three Mobile On Linux Update

UPDATE: After installing three mobile on Fedora 11 I noticed that the DNS servers had changed. The new one are as follows

DNS Server:,

One thing that I forgot to mention in my previous post about setting up mobile broadband on Fedora 11 is that three do not always set the correct DNS servers. This was annoying as it would appear that the connection was working however any attempt to access a website would timeout. In order to do so edit the connection via NetworkManager and add in the follow DNS server in the IPv4 tab.

DNS Server:,

The server addresses are comma seperated so you can add DNS server of your choice. I have used the DNS servers that Three normally set up you can use OpenDNS.

Network Manager IPv4 Settings

Sunday, 28 June 2009

Professional ASP.NET MVC 1.0

At work we have been looking at the ASP.NET MVC, model-view-controller, framework. After looking around at various different tutorials and articles we found a sample chapter from the wrox book Professional ASP.NET MVC 1.0. The sample chapter took the hello world example and create a full application. The application, NerdDinner is an application that allows you to create dinner parties and RSPV to them. The sample covers a lot of the functionality that is within ASP.NET MVC. The sample chapter can be found online at Wrox's website with the source code hosted at codeplex.

Professional ASP.NET MVC 1.0

Reading though the sample chapter is a good way to get started with ASP.NET MVC as the chapter explains what it is doing in a easy to understand manor, but more importantly it explains why they are being done. The chapter is a comprehensive walk through of how to create the NerdDinner application. Throughout the chapter the authors provide titbits of useful information, for example the use of the repository pattern and dependency injection. Throughout the chapter the authors trying to enforce good coding practice and often make reference to test driven development which in a later chapter they go into more detail about, discussing different development techniques.

The sample chapter is more than enough to get anyone started with ASP.NET MVC and follows the development process from start to finish including a section on unit testing the application. The following chapters delve into more detail about specific areas of the ASP.NET MVC framework. The second and third chapters go into detail about the MVC pattern, detailing its background and its use on the web. The chapter also provides an overview, albeit brief, of other frameworks that are available. Although their coverage was brief they were not mentioned as either superior or inferior rather just as alternatives to the ASP.NET MVC framework. This tone was subsequently repeated in the third chapter when the authors compare ASP.NET with WebForms to ASP.NET MVC. They often mention that MVC is not a replacement for WebForms rather it is a different approach. These two chapters are extremely useful as they allow you to make an informed decision whether ASP.NET MVC is the right choice for you.

I've still to finish reading the rest of this book so I'll update this post the more I read of it.

Saturday, 20 June 2009

Python and MSSQL

I have been playing about with django a fair bit over the last week. After written a small app with django I wanted to import some data from an existing MSSQL database. To get the data into the django model I created a seperate python script to perform the import. Below is a script to import data from a table compaines in a mssql data to a django model called Company. To connect to the mssql server I used the pymssql library.

#!/usr/bin/env python
import sys,os
os.environ['DJANGO_SETTINGS_MODULE'] ='settings'
# import the modules needed to start the import
import pymssql
from datetime import *
import unicodedata
from django.core.management import setup_environ
import settings


#import the django models
from apps.clients.models import *

def importCompanies(conn):
cur = conn.cursor()
FROM companies""")
row = cur.fetchone()
while row:
company = Company()
company.pk = row[0]
company.Name = row[1]
row = cur.fetchone()

if len(sys.argv) != 5:
print 'data_import.py [server] [username] [password] [database]'
print 'host=%s, user=%s, password=%s, database=%s' % (sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
conn = pymssql.connect(host=sys.argv[1], user=sys.argv[2], password=sys.argv[3], database=sys.argv[4])

After this I started to play around with pymssql I wanted a quick way to execute simple sql queries, not knowing of an linux alternative to the mysql console client I write another simple script to provide this basic functionality.

#!/usr/bin/env python
import sys,os
import _mssql

if len(sys.argv) != 5:
print 'data_import.py [server] [username] [password] [database]'
print 'host=%s, user=%s, password=%s, database=%s' % (sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
conn = _mssql.connect(server=sys.argv[1], user=sys.argv[2], password=sys.argv[3], database=sys.argv[4])
print '>',
cmd = raw_input()
while cmd != 'exit':
if cmd != '':
print cmd
for row in conn:
for i in range(0,( len(row) / 2 )):
print row[i],'|',
print ''
except _mssql.MssqlDatabaseException,e:
print e
print '>',
cmd = raw_input();


You can download mssql_client.py here

So after only using for python for a couple of weeks It's definitely powerful and fun to code with. Now to try out for all of the libraries that provide bindings such as pysvn or pyldap.

Tuesday, 16 June 2009

Fedora 11 and Mobile Broadband

When I was previously running F10 I managed to get my three mobile broadband setup without any hassle, which I conveniently forgot how to do when I install Fedora 11. After a quick search I found a comment on the redhat bugzilla. I have the ZTE MF622 usb modem from Three. Here the steps I followed to get it up and running.

Install usb_modeswitch, this changes the device from a CD Drive to a usb modem.

#as root
yum install usb_modeswitch

Edit the /etc/usb_modeswitch.conf and uncomment the section that related to your specific modem. This tells usb_modeswitch which modem you are using.

# ZTE MF622 (aka "Onda MDC502HS")
# Contributor: "andylog"

DefaultVendor= 0x19d2
DefaultProduct= 0x2000

TargetVendor= 0x19d2
TargetProduct= 0x0002


Now edit the udev rules to add a new line to automatically call the usb_modeswitch when the device is plugged in.

vi /etc/udev/rules.d/70-persistent-cd.rules

Append the following to the end of the file

ACTION=="add", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="2000",

Once this has been done run the following and then plug your modem in

udevadm control --reload-rules

You should now be ready to create a mobile broadband connection via NetworkManager.

Saturday, 13 June 2009

Fedora 11 is out, upgrade time

So Fedora 11 has been out for a little while now and I'm getting ready to upgrade. Previously I have tried using the upgrade facility however I normally end up having to perform a clean install. So now I'm currently backing up my home directories to my external storage ready to wipe everything and start again. Ill update how this goes.

Update: Install was painless simple selecting of packages that wanted to install. However my internet connection was playing up which meant that it hung whilst trying to download packages from the net. Currently installing the nvidia packages from rpmfusion.

Update Everything is up and running and I have restored all my data back on. A few problems and annoyances. There is a problem with the non-free nvidia driver. The only other annoyance is the System -> Preferences menu is not split into further sub menus which creates a menu that doesn't fit on my screen. I have yet to have a proper play with everything else but so far it all looks good.

Friday, 12 June 2009

Django and Python

I have recently started having a play about with django. After reading loads of about it and have a little play about with snowy (a django based note sync for tomboy). After getting used to coding in python I found django really quick to develop in. But the documentation is by far the best thing about the project. There's loads of the stuff, and its brilliant. Its readable. Its completely unlike reading other tech documents. If this isn't a good selling point for checking it out then I don't know what is because RTFMing has never been so easy.

Unit testing jQuery plugins with jqunit

Whilst creating a plugin for jquery, that would provide auto formatting for a textbox for numeric values, I was looking for a way to run the tests for confirm its functionality. After getting sick of running the tests manually the penny dropped that I could unit test the plugins functionality. After a little searching I came across jqunit that seems to fit the bill perfectly.

The project is hosted over at google code. The tests them self run from a html file but the a template is provided with the jqunit library. The tests are simple to create and follow the jquery syntax style. Below is a smple test case with unit test

var numericTestCase = new jqUnit.TestCase('jQuery.numeric - decimal',function(){



numericTestCase.test('T1: Null Value ',function(){
var txtInput = $("");


Tests can quickly be written to test the functionality of your code. With the testing being able to run form a single location it provides a quick an easy way to check your plugins work across multiple browsers, that is, as long as you have written the correct tests.