Archive for December, 2007

More Python, WSGI, moinmoin, and pycoon Notes

WSGI is pretty cool stuff - I messed around with cherrypy today, and enjoyed what I found. For a fairly small codebase its quite flexible and competent. I was reading a bunch of code from moinmoin and pycoon and took some notes…

moinmoin notes:

* function description comes after “def functionname:”
* php session parser very interesting…
* Can you save PHP bytecodes to a file like .pyc files?

lists = [1,2,3]

tuples = (1,2,3)

dictionaries = {1: "ablh"}

The colon is a great character, and python makes swell use of it.

=====

private functions in python start with __, everything else is public. Ian of the Paste project seems to think that these type of private functions are a bad idea though.

CherryPy

I’ve been reading up on CherryPy too - this is a great read. They have a page of templates and they don’t trash talk xslt - good! :-)

Paste

I haven’t actually tried out Paste yet, but the docs are very good. They explain a lot of what WSGI applications are all about. I read up on the WSGI spec too.

That leads me to another thought - I need to get more comfortable with how the python libraries and packages are installed. I may be wrong, but it feels like the packaging and path setup for python is a little haphazard.

PHP versus python

Just some comparison notes…
* PHP’s “this” is like python’s “self”
* PHP’s constructor class functions/methods are like python’s __init__ class functions/methods
* both languages are down with the idea of camelCaseForMethodNames

PHP foreach:

$blah = array("a","b","c");
foreach ($blah as $barf)
{
    echo $barf;
}

Python for:

blah = ["a","b","c"]
for barf in blah:
    print barf

My personal opinions:
* I like the dot syntax of python for referencing objects and methods, reminds me of javascript and actionscript
* Lists, tuples, and dictionaries still confuse me a little, but I’m figuring it out
* For some strange reason I feel more comfortable with self than this

Bulletproof AJAX (and Object Persistence)

ajax-header.jpg

As a follow up to my last post about javascript libraries, I’m now reading “Bulletproof AJAX” by Jeremy Keith. I’m pleased with what I’ve been seeing in javascript lately. Javascript developers have definitely caught the open source bug, and I hope this will lead the primary browser developers to continue to work towards accepting standards (don’t want to mention any names *cough* *cough* Microsoft!).

I just read a few pages and I’m glad I’m reading it. It reinforces my feeling that raw XML handling is not the best javascript. It there were better XSL support, I might be into it, but there isn’t, so while libraries like taconite look good, server side solutions to produce json look good too. I’ve flip-flopped on this issue a few times to say the least, and I think it might make sense to choose on a case by case basis.

At any rate, my thoughts about javascript and AJAX have reminded me how I’ve avoided object persistence on the server side too long. I’ve patched the need for it by leaning on the database, but that isn’t too helpful. If I get the chance today I hope I can read up on object persistence in PHP and python. If anyone has any pointers - please share! Thanks.

I also just jumped ahead to the section on “Progressive Enhancement” - which in the preview is one of the reasons why I chose this book. It reminded me of the way I like to develop: start simple and basic, make sure that objective tasks can be completed, then improve the user interface to make the processes faster and more intuitive. This process is a whole lot easier when dog-fooding! :-)

Javascript Libraries




javascript-header.jpg

I started this post several months ago and finally got around to examining some of these libraries. So far, I really like the jQuery library, and of course Sarissa. I like the idea of XSL transformations in Javascript, but it doesn’t really work that well as far as I can tell. Its possible with jquery and sarissa, but its a little cludgy. With jQuery, you can interact with the DOM in pretty clean manner, so maybe XSLT isn’t the best choice for client side.

Prototype looks good too, but I haven’t explored it too much.

* http://docs.jquery.com/Main_Page
* http://script.aculo.us/
* http://simonwillison.net/2006/Jun/26/libraries/
* http://developer.yahoo.com/yui/
* http://edevil.wordpress.com/2005/11/14/javascript-libraries-roundup/
* http://www.howtocreate.co.uk/jslibs/

I think that for my use XML and XSL will stay on the server, and the client side will only use JSON.

Good article on XML, HTML, and JSON:
* http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html

There are some nice json libraries:
* http://code.google.com/p/xml2json-xslt/ - converting data sets to json with XSL is a pretty neat idea, huh?
* http://www.ibm.com/developerworks/xml/library/x-xml2json/
* http://us3.php.net/json
* http://undefined.org/python/#simplejson
* http://pear.php.net/pepr/pepr-proposal-show.php?id=198

E4X looks interesting too, but of course Microsoft lacks support for this standard:
* http://www.w3schools.com/e4x/e4x_browsers.asp

I’m having a blast with jQuery. I just added tablesorter to PBooks and 1. it was easy and 2. it works really well. I then found this:

http://malsup.com/jquery/taconite/

which might be the right solution for me. I’ve been wavering between XML and JSON for updating content, and I think this might clinch the deal for XSL. I don’t think I’ll be doing many heavy AJAX data downloads, instead downloading all the data in one fell swoop and then perusing it with a method like the tablesorter pager.

pfSense IPSec with Mac OS X Clients

I just got IPSec running from an OS X client to a FreeBSD pfSense server. It won’t go natively because the Mac OS X client uses L2TP, but that isn’t supported by pfSense at this time.

IP Securitas can use plain IPSec and has enough control over the connections to set what you need to for it to work. I used the m0n0wall directions for roaming clients which are basically the same as those for a tunnel, but you must use aggressive instead of main.