Revision 622: /code/obj-c/OAuthConsumer

Posted 05 August 2008 in links tagged with [oauth] [objectivec] [programming]

an Objective-C oauth consumer library. For doing something with on the iPhone. Not sure what. Something.

http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/

 

Revision 622: /code/obj-c/OAuthConsumer

Practical threaded programming with Python

Posted 09 July 2008 in links tagged with [programming] [python] [threads]

 

Practical threaded programming with Python

Cocoa Programming for Mac OS X

Posted 12 June 2008 in photos tagged with [book] [cocoa] [macos] [programming]

 

Cocoa Programming for Mac OS X

ElementTree Overview

Posted 25 April 2008 in links tagged with [elementtree] [programming] [python] [xml]

One of the better python XML libraries. Ships in core python.

http://effbot.org/zone/element-index.htm

 

ElementTree Overview

Learning Ruby using Rails

Posted 16 November 2007 in blog tagged with [programming] [python] [rails] [ruby]

Recently I got dropped in the deep end and had to learn both Ruby and Rails very quickly. I didn’t think this would be a problem - everyone raves about how easy Rails is to pick up, right? - and it wasn’t. The problem is actually arriving now, as I start trying to use Ruby for things other than Rails applications. And I can’t, because I’ve learned all sorts of nice Ruby tricks that looked like they were core language features but actually turn out to be added to the built-in Ruby objects by Rails.

For instance, I really like the 3.days convention for turning numbers into time intervals. That’s added by this extension. In fact, in digging for this, I found out just how many things Rails adds to core Ruby. I’m scared.

I’m torn. I’d like to consider messing with the built in objects confusing and dangerous. And I’ve been bitten by this before. I’ve also had problems where one module’s patching to a Ruby builtin interferes with another module’s patching of the same object. Lovely.

At the same time, though, I love it. I love both the huge convenience and readability of being able to write Time.now + 3.days, and the fact that the language lets me do this. All languages should be this consistent - none of this ‘some types are special’ crap.

There are trade-offs. I love Python, but I hate that map is a global function and not a method on arrays, and I hate that certain types are special and immutable. But I’m sure there are scary speed benefits from doing things this way.

I wonder if part of the reason that Ruby has this ‘just for Rails’ reputation is because, having learned Ruby for Rails, you can’t use that Ruby for anything else without unlearning a stack of habits?

 

Optional catch in JavaScript

Posted 26 July 2007 in blog tagged with [exceptions] [javascript] [programming] [rhino] [spidermonkey]

One of the things that’s been annoying me about JavaScript recently is the inability to only catch certain classes of exception, as in Java or Python, for instance. The try {..} catch(e) {..} block has always seemed too inclusive. But recently Ash found a crazy syntax in SpiderMonkey that lets us only catch certain exceptions.

try {
  // something that can throw
} catch(e if e.bar == 'foo') {
  // an error is only caught here if it has a 'bar' property of 'foo'
} catch(e if e.bar == 'baz') {
  // there can be different catches for different conditions
} catch (e) {
  // otherwise it's caught here. Without this block, the error would fall
  // through the 'try' and be re-thrown.
}

I haven’t bothered testing this in Internet Explorer (or any other web browser for that matter), because I’m only interested in server-side JavaScript execution at the moment. It works in at least recent SpiderMonkey CVS and Rhino 1.6r6, not sure about earlier versions.

 

mod_js - a JavaScript Apache module

Posted 09 July 2007 in code tagged with [apache] [javascript] [programming] [spidermonkey]

[mod_js](http://jerakeen.org/code/mod_js) is an Apache module written by Ash Berlin and I that embeds the SpiderMonkey JavaScript engine and lets you run JavaScript code on the server as CGI scripts. As you’d expect, it’s very early, but is good enough to compile scripts, run the JavaScript, and print the output to the client. mod_js is licensed under the GPL3.

read more (231 words)..  

Server-side JavaScript under Apache

Posted 09 July 2007 in blog tagged with [apache] [javascript] [programming] [spidermonkey]

Ash Berlin and I recently hacked together an Apache module that embeds the SpiderMonkey JavaScript engine and lets you run JavaScript code on the server as CGI scripts. We called it mod_js.

read more (264 words)..  

the Blogger, Movable Type and MetaWeblog XMLRPC APIs

Posted 26 February 2007 in blog tagged with [cms] [programming] [xml]

There are 3 different XMLRPC APIs for editing blog posts. I really don’t like the Atom Publishing Protocol, but given the state of the alternative, I can see why other people do..

read more (342 words)..  

Yet more E4X irritations

Posted 30 January 2007 in blog tagged with [javascript] [programming]

I’m finding E4X to be one of those weird technologies that is alternately utterly wonderful and incredibly irritating. The ability to treat XML data as any other JavaScript data structure allows very fast app development and messing around, but every so often I find myself amazed at how awful the syntax is.

Today’s irritation is about E4X attributes.

// a perfectly normal E4X object.
var myXML = <xml foo="bar">content</xml>;

// the attribute with value 'bar'
var myAttribute = myXML.@foo;

Easy. I love this stuff. Unfortunately, Zimki, my company’s product, uses uneval to store complex objects, and the myAttribute variable there would count. uneval won’t produce JSON but it does produce a string that, when run through eval, will probably produce the original data structure, and we store that string in a database to store object.

Not so for E4X nodes. Playing in the SpiderMonkey JS console,

js> uneval( myXML );
<xml foo="bar">content</xml>

js> uneval( myAttribute );
bar

The first one is fine. That string will eval nicely back to the original E4X object. But the ‘bar’ there isn’t valid JavaScript - eval won’t restore the original object. In fact, had the original XML been something like:

<xml foo="delete_all_zimki_data()">bar</xml>

and we’d tried to use eval/uneval to store this XML, we’d have executed the attribute as JavaScript. Ick.

Unusually, Rhino handles this much better (normally I find Rhino lags in features..):

js> uneval( myAttribute );
<>bar</>

Not really an attribute node any more, but at least it’s valid JavaScript and won’t destroy my server.

I don’t even have a good solution for this. Right now I’m fudging E4X nodes in the storage engine, but I really feel that attribute nodes should uneval to something a little more sensible. Perhaps I’ll be able to produce a patch to SpiderMonkey, if I have time..

 

LSL Wiki : HomePage

Posted 21 November 2006 in links tagged with [lsl] [programming] [secondlife]

 

LSL Wiki : HomePage

Cocoa Dev Central: Building Easy Sheets

Posted 16 November 2006 in links tagged with [cocoa] [programming] [sheet]

sheets in cocoa. Because it’s not clear how to close them safely otherwise.

http://cocoadevcentral.com/articles/000014.php

 

Cocoa Dev Central: Building Easy Sheets

Ignoring resource fork files files with subversion

Posted 31 October 2006 in blog tagged with [macos] [programming] [subversion]

If you’ve ever edited files over samba, or on a fat partition, using a mac, you’ll know that it scatters annoying ._foo.txt files all over the place when you save things. These files are the system’s way of compensating for these filesystems not supporting ‘real’ resource forks, and they’re a complete pain. I feel this pain especially when I’m trying to see what’s changed in a subversion checkout using svn st, and it produces 30 lines of ? ._foo.pl complaints.

Fortunately, subversion allows you to ignore this stuff. Edit the file ~/.subversion/config (which is created the first time you use the subversion client), and search for the ‘miscellany’ section. Uncomment the line [miscellany] if it’s not already, and also uncomment the line beginning global-ignores. This line is a list of glob patterns for files that should be ignored when doing a svn st, or svn add (if you svn add on a folder, it won’t add any backup files in the folder, for instance). Add the pattern ._* to the end of it, and your resource fork woes are over…

 

On “Strongly Typed” Languages

Posted 16 October 2006 in links tagged with [programming] [strong] [typing]

 

On "Strongly Typed" Languages

JavaScript Lint

Posted 20 September 2006 in links tagged with [javascript] [lint] [programming]

Check JS code for silly errors - missing trailing semicolons, etc, etc. A nice idea.

http://www.javascriptlint.com/

 

JavaScript Lint

CamelBones, an Objective-C/Perl bridge for Mac OS X & GNUStep - Release Notes - 1.0.0

Posted 11 July 2006 in links tagged with [cocoa] [mac] [perl] [programming]

Camelbones 1.0. Congratulations to Sherm

http://camelbones.sourceforge.net/documentation/history/d...

 

CamelBones, an Objective-C/Perl bridge for Mac OS X & GNUStep - Release Notes - 1.0.0

GTK+ 2.0 Tree View Tutorial

Posted 10 June 2006 in links tagged with [gtk] [programming]

I really hate the way that the GTK+2 tree view works. The amount of setup you have to do is scary. But then, I’m just too used to cocoa.

http://scentric.net/tutorial/

 

GTK+ 2.0 Tree View Tutorial

NodeBox

Posted 04 June 2006 in links tagged with [graphics] [macos] [programming] [python]

things to play with when I get back to a desk that has a mac on it.

http://nodebox.net/

 

NodeBox

Nearly All Binary Searches and Mergesorts are Broken

Posted 04 June 2006 in links tagged with [google] [maths] [programming]

[[ It is not sufficient merely to prove a program correct; you have to test it too ]]

http://googleresearch.blogspot.com/2006/06/extra-extra-re...

 

Nearly All Binary Searches and Mergesorts are Broken

C# From a Java Developer’s Perspective

Posted 25 May 2006 in links tagged with [c#] [java] [programming]

 

C# From a Java Developer's Perspective

isinstance() considered harmful

Posted 25 May 2006 in links tagged with [programming] [python]

python prefers objects to implement an interface, rather than forcing them to subclass things. This is most obvious to be when it comes to file objects, but it applies across the whole language. Perl does this to a much smaller extent, but you could also

http://www.canonical.org/~kragen/isinstance/

 

isinstance() considered harmful

JavaScript strings - a followup

Posted 12 May 2006 in blog tagged with [javascript] [programming]

Having played around with the JavaScript string type some more, I think I understand why it acts as it does. I’m a Perl monkey normally, so I’m not used to the concept of immutable strings, but JavaScript strings are immutable. Playing with the === operator (approximately, ‘is this the same object’) gives:

js> "a" === "a";
true
js> "a" + "b" === "ab";
true
js> "ab".replace(/./, "c") === "cb";
true

but

js> new String("a") === new String("a");
false

If strings were to magically upgrade themselves to objects, they’d change behaviour - previously equivalent strings would suddenly not be equivalent. Likewise, suppose this worked:

var a = "string";
var b = "string";
a === b; # true
a.foo = 1;

Shoud a still be equivalent to b? If not, a clearly isn’t immutable, as we’ve changed it. But if it is, then we’ve chanaged b at a distance - it’s grown a foo attribute.

Still all very annoying, of course, but I understand why now.

 

JavaScript string weirdness

Posted 29 April 2006 in blog tagged with [javascript] [programming]

Recently, I mentioned a peculiar difference between uneval and toSource. Specifically (using the SpiderMonkey JS console):

js> uneval("");
""
js> "".toSource();
(new String(""))

"" and new String("") are different types of objects. The first is the basic string type, and only really has a value. The second is a full Object, that happens to have a value. However, it turns out that if you treat a basic string type as an Object, say by putting ‘.’ after it in an expression, the SpiderMonkey runtime will implicitly promote the string to a String. Hence, "".toSource() promotes the string object, then calls toSource on the new String object.

Annoyingly, the String Object doesn’t hang around, it’ll get thrown away as soon as you’re done with it. This leads to the weird case that you can set attributes on a basic string type (because it’ll get promoted to an Object, and Objects have attributes) but they don’t stay set (because the Object you’ve set them on gets thrown away as soon as the set call finishes).

By the way, all of this applies very specifically to the current CVS trunk SpiderMonkey. I don’t know what most web browser engines do with strings, so don’t assume this applies in, say, Internet Explorer. But I’d be interested if someone wants to find out and tell me…

 

uneval() does not produce JSON

Posted 22 April 2006 in blog tagged with [javascript] [programming]

More playing with JSON and Spidermonkey has revealed yet another incredibly annoying fact (I hate those guys). Spidermonkey provides a lovely uneval() function, that does the exact opposite of eval() - turns JS objects into strings. It works on almost everything, and make life very very nice. There’s also Object.toSource() which does something similar (but not the same - try uneval("") vs "".toSource()).

But the strings that uneval produce are not valid JSON, as I have been assuming. I’ve been getting steadily more worked up at all the JSON parsers in the world, refusing to parse things that are clearly valid JavaScript, and eventually I go look at the spec, which fails to list ' as a valid string delimiter. And guess what delimiter uneval produces? Yay. So all the parsers are fine, and it’s just SpiderMonkey that’s broken.

Fortunately, Mochikit provides a nice serializeJSON() function.

 

Simon Wistow / Lingua-EN-Keywords-Yahoo-0.5 - search.cpan.org

Posted 22 January 2006 in links tagged with [extraction] [keyword] [programming] [tags]

 

Simon Wistow / Lingua-EN-Keywords-Yahoo-0.5 - search.cpan.org

Alice: Free, Easy, Interactive 3D Graphics for the WWW

Posted 22 January 2006 in links tagged with [graphics] [programming]

 

Alice: Free, Easy, Interactive 3D Graphics for the WWW

Particletree · Quick Guide to Prototype

Posted 30 November 2005 in links tagged with [development] [javascript] [programming] [reference] [web]

 

Particletree · Quick Guide to Prototype

Helpful Tiger: It Only Hurts When I Laugh

Posted 28 November 2005 in links tagged with [development] [pragmatism] [programming] [tests]

On test-driven development in the real world - [[ All these are ugly solutions, design-wise. And Feathers knows it; he makes multiple apologies for his techniques. But he stresses that they work. ]]

http://www.helpfultiger.com/helpfultiger/2005/11/it_only_...

 

Helpful Tiger: It Only Hurts When I Laugh

NewsGator API Homepage

Posted 27 November 2005 in links tagged with [blog] [programming] [reference] [rss] [web] [xml]

 

NewsGator API Homepage

TrimPath JavaScript Templates Demo

Posted 23 November 2005 in links tagged with [javascript] [programming] [template] [web]

Javascript templating language. Completely insane.

http://trimpath.com/demos/test1/trimpath/template_demo.html

 

TrimPath JavaScript Templates Demo

The London Perl Workshop 2005

Posted 28 October 2005 in links tagged with [conference] [london] [lwp] [perl] [programming] [workshop]

 

The London Perl Workshop 2005

further notes on JSON

Posted 16 October 2005 in blog tagged with [javascript] [programming]

Off I go, making random unsubstantiated claims about the danger of using JSON with non-ASCII characters. This called for a Test. So I wrote one. Visit my JavaScript unicode test page and see how your browser interprets external JavaScript files - I serve an ‘é’ using JavaScript to the page via 3 methods and 2 character set encodings, and try to render them all.

My conclusions from some limited testing? Owch. You can’t include a JavaScript file and expect the client to interpret it properly, unless you control both the server serving the JavaScript and the HTML page requesting it, and can make sure that they’re both in the same character set. Alternatively, you can escape all non-ascii characters in your JavaScript files using the \xXX or \uXXXX notations, which seems to work everywhere I’ve tried, but also seems like a pathetic work-around. Anyway, needing a work-around for only the non-obvious case means that no-one will actually do it, because no-one ever seems to bother testing with non-ASCII (see any on the JSON examples page, for instance?).

However, requesting JSON using XMLHTTPRequest seems to do the Right Thing in every browser I’ve tested, including those that include JavaScript wrongly. So if you’re using JSON as an RPC transport, instead of XML, for instance, it looks safe. From a character-set point of view.

 

The Programmer’s File Format Collection

Posted 12 October 2005 in links tagged with [file] [format] [programming]

 

The Programmer's File Format Collection

JSON

Posted 12 October 2005 in blog tagged with [javascript] [programming]

In the bad old days of web 1.7ish, the cool thing to do for dynamic web applications was to generate HTML snippets on the server-side, pull them into your app using XMLHTTPRequest, and shove them bodily into a DIV on the page somewhere. “generating DOMs is hard” was the excuse, “the server already has a nice templating language”, etc, etc. And this was Good.

Nowadays, of course, this is Evil. Pulling HTML across the wire? It’s inefficient! Even worse, we want to send XHTML to the client, because it’s cool, but then you can’t treat your HTML like a string, you really do have to mess with DOMs. Fortunately, cute tools like MochiKit make it really easy to create DOM nodes, and provide really nice tools for making ajax requests. We see the rise of JSON - serializing your raw data on the server into a JavaScript-evaluatable string and sending that across the network, then building the DOM on the client side based on that data. And this is Good.

Soon, I expect, people will run up against annoyances in JSON. For instance, I bet there are lurking character set issues. It’s also not very portable - if I go to all the trouble of writing and exposing interesting functions of my web application in machine-readable ways, I’d like to be able to access this data using things other than javascript. Sure, there are modules like JSON that will both create and parse these things, but throwing actual XML around seems much neater to me.

We have a strange mix of XML and JSON APIs at the moment, some toolkits even making it easy to ask for either. But I consider XML far superior for this sort of thing, if only because the character set issues (my personal bugbear) are properly solved with XML. It’s disadvantage is that the JavaScript tools for dealing with the DOM are very annoying, but when we have something like XML::Simple or xmltramp for JS, and reading incoming XML is almost as easy as reading JSON, we can get rid of it and use nice sensible RPC mechanisms. JSB is a lovely example of this, for instance. And this will be Good.

 

-Ofun

Posted 09 October 2005 in links tagged with [philosophy] [programming]

 

-Ofun

search.cpan.org: Perl::Review - Engine to critique Perl souce code

Posted 22 September 2005 in links tagged with [perl] [pierre] [programming] [review]

 

search.cpan.org: Perl::Review - Engine to critique Perl souce code

The State of Linux Graphics

Posted 14 September 2005 in links tagged with [linux] [programming] [software] [x11]

 

The State of Linux Graphics

The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software

Posted 08 September 2005 in links tagged with [concurrency] [cpu] [programming] [threading]

 

The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software

Rands In Repose: What To Do When You’re Screwed

Posted 19 August 2005 in links tagged with [management] [programming] [software]

 

Rands In Repose: What To Do When You're Screwed

Unicode HOWTO

Posted 07 August 2005 in links tagged with [programming] [python] [unicode]

 

Unicode HOWTO

Copia

Posted 06 August 2005 in links tagged with [programming] [python] [unicode]

 

Copia

Open Source ODBEditor

Posted 30 July 2005 in links tagged with [cocoa] [mac] [programming]

 

Open Source ODBEditor

Joel - Back to Basics

Posted 09 October 2004 in links tagged with [fundamentals] [joel] [programming]

 

Joel - Back to Basics

Joel - The Joel Test

Posted 09 October 2004 in links tagged with [joel] [programming] [quality]

 

Joel - The Joel Test

Joel - Why exceptions are bad

Posted 09 October 2004 in links tagged with [exceptions] [joel] [programming]

 

Joel - Why exceptions are bad

Alan Cox on writing better software

Posted 09 October 2004 in links tagged with [programming] [quality]

 

Alan Cox on writing better software

More things I don’t like about Python

Posted 21 September 2004 in blog tagged with [programming] [python]

I’ve played with python some more, and there are more things I don’t like about it.

For objects, attributes and methods are called with the exact same syntax, the ‘.’ character. So for an object ‘foo’, foo.bar is the attribute (member variable) ‘bar’ of foo, and foo.baz() is a function call on the method ‘baz’ of the foo object. But if a foo object has an attribute ‘bar’ and a method ‘bar’, foo.bar gets the attribute, and foo.bar() explodes, because an attribute isn’t a function. I don’t like that you can hide functions behind attributes.

More object stuff - there’s no abstract ‘call my superclass method’ calling convention. You have to either explicitly call a class method on your superclass (calling it by name, so changing your superclass would be Pain) and passing ‘self’ as the first parameter, or you use the magic ‘super’ method, which requires you to pass your class explicitly, also meaning Pain if you rename things. Hello? self.super? Sigh.

Incidentally, there are plenty of things about python I’m really liking - it’s not all pain. But people don’t blog about things that they like, they blog about things that annoy them. Human nature - deal with it.

 

programming languages

Posted 14 August 2004 in blog tagged with [programming]

Programming languages have grammar. There are languages like perl, where the grammar is composed almost entirely of random ‘$’ and ‘%’ symbols scattered throughout the code. And there’s languages like AppleScript, where the grammar is practically english, making it much nicer to read than perl. Hah, perl is often called a ‘write-only language’, it’s so incomprehensible.

But I loathe Applescript, and I think perl is luuurvely. And it’s for this exact rule. I can use computers. I’m a geek. And I’m prepared to learn a new grammar. That’s fine, and it’s a specialist grammar, and programming is like that, I’ve learnt a heap of these things. But english-like programming languages are confusing. I can speak english. I know how it works. In english, you can rearrange words and have the sentence still make sense. Try doing that in Applescript. Grammars that look like english, but aren’t actually english, annoy the hell out of me.

 

Reinvented Wheels

Posted 01 January 2000 in code tagged with [programming]

Wheels that perl programmers always end up reinventing.

read more (49 words)..