Skip to main content

Posts

Python Contributor!

I'm rather proud to report that my first contribution to the Python code base has been committed in changeset 80421 . To aid in my nostalgia I'm going to discuss what I did and why. It started a long time ago, I think this post by Jesse Noller  inspired me. A new mailing list was set up to encourage more core development, the aim was to get new contributors to the Python codebase. At the same time the Python developers guide was  heavily edited and was made available at  http://docs.python.org/devguide/ The call was put out for simple contributions - documentation, examples, improving testing coverage for the standard library and relatively easy beginner tasks to become familiar with the development process. Using a coverage tool written by Ned Batchelder I generated a list of test coverage for each standard library module. After looking down the list of modules with low test coverage I decided to tackle functools . This was a good trade off in terms of its t...

Python3 Websocket Server

This is a follow up post combing pure Python  Bluetooth  sockets with pure Python websockets. Pure Python meaning no imports outside of the standard library and not using ctypes. I decided my i-Racer car needed to have a much better user interface than my Python3 API. I mean when I first got it, typing  car.forwards() was enough to impress me but no longer. For a while now I've been wanting to invest some of my time getting better at this web stuff. One of the suggestions I got prior to my Kiwi PyCon talk was to use websockets , problem was I didn't know much javascript yet alone websockets! I started by looking at the Python libraries that implement websockets, tornado has one but I didn't want a whole web framework. The largest library is mod-pywebsocket . Unfortunately their API doesn't appear to easily lend itself to extension, and it is only Python2 which wouldn't play nicely with my Python3 bluetooth socket connection to the car. Their example appli...

Bluetooth with Python 3.3

Since about version 3.3 Python supports Bluetooth sockets natively. To put this to the test I got hold of an iRacer from sparkfun . To send to New Zealand the cost was $60. The toy has an on-board Bluetooth radio that supports the RFCOMM transport protocol. The drive  protocol is dead easy, you send single byte instructions when a direction or speed change is required. The bytes are broken into two nibbles:  0xXY  where X is the direction and Y is the speed. For example the byte 0x16 means forwards at mid-speed. I was surprised to note the car continues carrying out the last given demand! I let pairing get dealt with by the operating system. The code to create a  Car object that is drivable over Bluetooth is very straight forward in pure Python: import socket import time class BluetoothCar : def __init__ ( self , mac_address = "00:12:05:09:98:36" ): self . socket = socket . socket ( socket . AF_BLUETO...

An open letter to Kiwibank

Dear Kiwibank, My suggestion isn't actually sensitive hence posting it on my blog. This could be a game changer for Kiwibank though. I want support for requesting payments. I've run into "POLi" before, and it's rubbish - the fact it requires a particular operating system and browser, requires letting untrusted third-party code log into the user's bank account and "take control". Terrible for an untrusting geek like myself who wants to pay for a flight... I realize POLi isn't the problem, or a Kiwibank product, but it is the current best solution because no bank is willing to lead and create a proper (and secure) solution to real time paying with online banking. It would be a great benefit to many people, including trademe users, and small businesses who might need to take payments and deposits online. Heres how I imagine it could work: People wanting paid would be able to go to kiwibank.co.nz set up and email their payment request/invo...

Socks

There is certainly some confusion with sockets, as my flatmate put it; sockets connect stuff together right? Wikipedia puts it a little clearer with: sockets are inter-process communication endpoints That sounds pretty boring but I promise you can do some fairly interesting things with them. Sockets are a core part of the operating system, and a socket API is used to direct how the operating system should use sockets. So the hello world of sockets would have to be an echo server. Let's create a basic Python3 socket server that will listen on IPv6 and repeat what it hears. The Python Howto guide for sockets starts with this: Sockets are used nearly everywhere, but are one of the most severely misunderstood technologies around. On the server side, you follow these steps: Create a socket (possibly after querying the system for information) Bind the socket, which assigns the socket to an address Listen prepares it for incoming connections Accept an incoming connec...

Learning by doing

About a year ago I read a programming post by Peter Norvig: (How to Write a (Lisp) Interpreter (in Python)) , being a Python programmer, of course I had to try write my own Lisp interpreter as a way to learn lisp. My implementation is relatively short, but can do some surprisingly complex things like this Y Combinatorial Factorial from wikipedia (which is one of my unittests): ( begin ( define Y ( lambda ( f ) (( lambda ( x ) ( f ( lambda ( v ) (( x x ) v )))) ( lambda ( x ) ( f ( lambda ( v ) (( x x ) v ))))))) ( define fact ( Y ( lambda ( f ) ( lambda ( n ) ( if ( = n 0 ) 1 (* n ( f (- n 1 )))))))) ( fact 10 ) ) I've recently dug up the files, rinsed them off, and put them on my bitbucket account. The reason I took another look at this project was my desire to translate it with Pypy . After having to battle just to get the tokeniser into valid RPython to translate I'v...

Learning in an online world

Since I started at Dynamic Controls about two years ago, engineers have done free online courses in machine learning, artificial intelligence, cryptography and digital electronics. These services are just starting to build momentum, have a go at many computer science topics at coursera.org or udacity.com , for something completely different learn a language while transcribing the web at duolingo.com . The business also promotes internal classes, from topics related to each department like Finance 101 to classes run by enthusiasts in a particular domain like the Chinese language or Programming in Python. I'm about to embark on teaching the "Introduction to Programming" course for the third time. It is so rewarding to see many of my previous students use Python to automate some repetitive part of their job. Everyone has been happy using Python 3 as their first programming language. We live in a wonderful world with a rich culture of free learning and education.