Mac Daddy World » Blog Archive » Adventures in Cocotron
29 October 2008
in links
tagged with
[cocoa]
[development]
[porting]
[programming]
[windows]
“The primary shortcoming of the Cocotron project may be the lack of a flagship product to drive the effort. It became apparent once we started the port, that the creators weren’t actively using it to create a shipping application
”
Faking a message queue
10 October 2008
in notes
tagged with
[lazy]
[messages]
[programming]
[queue]
Right. Here’s an idea I want someone else to build, because I’m too lazy/busy. I want a Stomp interface to mysql.
Let me explain. There are lots of reasons you might want a message queue architecture in your new web application. You want long-running background processes, or you want to fan out changes to lots of users without tying up the web server process. Or you want to make calls to an API somewhere, again without tying up an expensive web server process. It’s a lot easier to build this stuff in from the beginning than to try to work out later which bits of your application flow don’t need to happen before the web page is returned to the user.
At the same time, it’s a tiny new web site. You don’t want to have to run a message queue just yet, so you want to fake it - write tasks into a database table, and have a long-running daemon loop forever, pulling out rows in order and doing them. Almost as good as a real message queue for small volumes of messages, and a lot cheaper. So what I want is a way of doing this that has the same API as a real message queue, so that when you cut over, you don’t have to change any code, everything just gets more responsive. Yay!
Right. Now someone do it. Let me know when you’re done.
blog.bjrn.se: Let’s build an MP3-decoder!
02 October 2008
in links
tagged with
[decoder]
[mp3]
[programming]
Nice guide on writing a (bad) mp3 decoder. Lovely low-level stuff that everyone should read. Reminds me a little of CypherSaber in that it’s something that I don’t ever need to do, but it’s nice to know how to do, or at least the basic principles.
The Continuous World of Dungeon Siege
27 August 2008
in links
tagged with
[dungeonsiege]
[games]
[programming]
Fascinating stuff about the techniques Dungeon Siege uses to power its continuous world. Includes scary threading, performance hacks, etc. via some other tab that’s long since been eaten by the ravages of time and system crashes (thank goodness for what little session saving Safari does) but I think I might have been tomc. (blech tells me it’s via Migurski’s uxweek notes )
Revision 622: /code/obj-c/OAuthConsumer
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.
Practical threaded programming with Python
09 July 2008
in links
tagged with
[programming]
[python]
[threads]
Cocoa Programming for Mac OS X
12 June 2008
in photos
tagged with
[book]
[cocoa]
[macos]
[programming]
Third Edition. Yay.
ElementTree Overview
25 April 2008
in links
tagged with
[elementtree]
[programming]
[python]
[xml]
One of the better python XML libraries. Ships in core python.
Learning Ruby using Rails
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
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
09 July 2007
in code
tagged with
[apache]
[javascript]
[programming]
[spidermonkey]
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.
Server-side JavaScript under Apache
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.
the Blogger, Movable Type and MetaWeblog XMLRPC APIs
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..
Yet more E4X irritations
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
21 November 2006
in links
tagged with
[lsl]
[programming]
[secondlife]
Cocoa Dev Central: Building Easy Sheets
16 November 2006
in links
tagged with
[cocoa]
[programming]
[sheet]
sheets in cocoa. Because it’s not clear how to close them safely otherwise.
Ignoring resource fork files files with subversion
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
16 October 2006
in links
tagged with
[programming]
[strong]
[typing]
greatest. slide. evar.
JavaScript Lint
20 September 2006
in links
tagged with
[javascript]
[lint]
[programming]
Check JS code for silly errors - missing trailing semicolons, etc, etc. A nice idea.
CamelBones, an Objective-C/Perl bridge for Mac OS X & GNUStep - Release Notes - 1.0.0
11 July 2006
in links
tagged with
[cocoa]
[mac]
[perl]
[programming]
Camelbones 1.0. Congratulations to Sherm
http://camelbones.sourceforge.net/documentation/history/d...
GTK+ 2.0 Tree View Tutorial
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.
NodeBox
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.
Nearly All Binary Searches and Mergesorts are Broken
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...
C# From a Java Developer’s Perspective
25 May 2006
in links
tagged with
[c#]
[java]
[programming]
A comparison
isinstance() considered harmful
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
JavaScript strings - a followup
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
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
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
22 January 2006
in links
tagged with
[extraction]
[keyword]
[programming]
[tags]
Particletree · Quick Guide to Prototype
30 November 2005
in links
tagged with
[development]
[javascript]
[programming]
[reference]
[web]
Helpful Tiger: It Only Hurts When I Laugh
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_...
NewsGator API Homepage
27 November 2005
in links
tagged with
[blog]
[programming]
[reference]
[rss]
[web]
[xml]
TrimPath JavaScript Templates Demo
23 November 2005
in links
tagged with
[javascript]
[programming]
[template]
[web]
Javascript templating language. Completely insane.
The London Perl Workshop 2005
28 October 2005
in links
tagged with
[conference]
[london]
[lwp]
[perl]
[programming]
[workshop]
Yay. I liked last year’s
http://london.pm.org/pipermail/london.pm/Week-of-Mon-2005...
further notes on JSON
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
12 October 2005
in links
tagged with
[file]
[format]
[programming]
JSON
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
09 October 2005
in links
tagged with
[philosophy]
[programming]
search.cpan.org: Perl::Review - Engine to critique Perl souce code
22 September 2005
in links
tagged with
[perl]
[pierre]
[programming]
[review]
The State of Linux Graphics
14 September 2005
in links
tagged with
[linux]
[programming]
[software]
[x11]
Rands In Repose: What To Do When You’re Screwed
19 August 2005
in links
tagged with
[management]
[programming]
[software]
Unicode HOWTO
07 August 2005
in links
tagged with
[programming]
[python]
[unicode]
Copia
06 August 2005
in links
tagged with
[programming]
[python]
[unicode]
Open Source ODBEditor
30 July 2005
in links
tagged with
[cocoa]
[mac]
[programming]
Joel - Back to Basics
09 October 2004
in links
tagged with
[fundamentals]
[joel]
[programming]
Joel - The Joel Test
09 October 2004
in links
tagged with
[joel]
[programming]
[quality]
Joel - Why exceptions are bad
09 October 2004
in links
tagged with
[exceptions]
[joel]
[programming]
More things I don’t like about Python
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
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
01 January 2000
in code
tagged with
[programming]
Wheels that perl programmers always end up reinventing.
