July 27, 2006

Minor victories

I’m now sufficiently proficient in Haskell to be able to manipulate large databases precisely how I want to. It makes my job that bit easier.

I managed to make GHCi crash too. I smell my first bug report!

Posted by Oliver at 03:22 PM | Comments (0)

July 12, 2006

Using Mac OS X's Cocoa without Objective C

I’m having real problems trying to work out how to interface with the Cocoa runtime on Mac OS X. F-Script, a “lightweight open-source scripting layer” for Cocoa, looks very good and also has a super-useful list of language bridges to the Cocoa runtime. The one I’m looking for, a Haskell-Objective C bridge, is there too. Unfortunately I couldn’t get the examples to work, and the project maintainers seem to have found more interesting things to be doing… which is a shame, as the bridge no longer compiles on Tiger.

Update: Spoke too soon here about HOC - I managed to compile it on 10.3. The trick is to update XCode to 1.5, and then apply a GCC update. Both updates are available from Apple’s Developer website but that requires registration and agreeing to their T & Cs. I’m sure there’s a way to update GCC without going the XCode updating route but I’m not clued in enough to puzzle it out…

Posted by Oliver at 04:06 PM | Comments (0)

February 26, 2006

A really quite involved example of a particular kind of laziness

I’ve been spending some of my time working my head around the programming language Haskell, using Paul Hudak’s The Haskell School of Expression book as a guide. It’s going quite well, and I’m working my way through the exercises fairly successfully, and really the only thing slowing me down is not making enough time to spend on it.

I always find though, when I’m getting my head around a new programming language - which isn’t something I try often, by the way, it’s just something I do to feed my pet fantasy that I could become self-employed via my programming skills but that I’ll need a super-effective language to do it with - but when I’m wrapping my head around a new language and amn’t feeling too lazy about it, I try to do the programming exercises. I get them perhaps 90% of the time, but there’s always one or two that don’t necessarily depend on your knowledge of the language, but instead rely on your knowing something entirely separate, like a particular mathematical formula, or some scientific nugget about physics. I suppose the point is that you go look that stuff up and work out how to express it in the programming language du jour. But sometimes it’s just obscure stuff you have to think about to work out, and I don’t know about you, but I find serious, patient thinking hard to maintain once thirty seconds have gone by. I need to be genuinely interested in what I’m thinking about, and far more often than not, these programming exercises aren’t that interesting. They can’t be; if they were, you might miss the technique you’re supposed to be hammering into your tired brain.

One classic example is this: Out of nowhere, you’re suddenly working in a shop, and you’re in the middle of serving a customer. This lovely customer (let’s call her Gertrude) has given you too much money for the goods she’s buying off of you, and so you have to give her change. But wait! What kind of change do you have, and how do you work things out so that you give Gertrude the lowest number of coins possible - don’t go giving her 53 pennies now!

Okay, for a human, this is not so tough. But trying to get the essence of the problem expressed in a programming language is a bit trickier. You have to derive an algorithm that, when given an amount owed and a list of coins available (fifty-cent pieces, twenty-cent pieces, etc.) will tell you how many of each kind of coin to give back.

The standard solution is that you pay with the largest coins first, until you have to move to the next largest coin, and so on. So if you’re owed 97 cents and you have fifty-cent, ten-cent and one-cent pieces on hand, you give back one fifty, four tens and seven one cent pieces. Although in that situation I’d probably check with the customer first to see if they had three cents, but I don’t think my programming textbook allows for that kind of thinking.

The optimal change problem a fairly common problem in programming textbooks for many different languages, and it’s quite satisfying to work out that the Haskell solution takes two lines, while a C++ solution could take 20 or more (at a guess). Assuming brevity of expression - without sacrificing clarity of expression - is a desirable trait in a programming language (for me it definitely is), Haskell seems well worth knowing.

But then, the twist. The 10% of problems I never manage to answer, whether due to boredom or impatience or because the solution requires some mathematical understanding I’ve no interest in pursuing. Like many programming books, The Haskell School of Expression has a website that includes, along with the usual software downloads, a list of errata. Mistakes made in the text. One of these is actually a footnote to the above problem, pointing out that the “obvious” solution isn’t necessarily the “optimal” one. What if, for example, you live in some manner of crazy universe where they have three cent pieces? You owe them six cents, and you have four-cent pieces, three-cent pieces, and one-cent pieces. Use the scheme described above, and you give them one four-cent piece and two one-cent piece. But the better solution would be to give them two three-cent pieces - that way they get fewer coins. So the solution above isn’t optimal.

What is? I don’t know. But it’s going to bug me until I work it out (cursory googling reveals nothing). Or until I forget about it. It’s at that point where I don’t quite care enough to justify thinking about it deeply.

There’s a certain class of person out there who might suggest that I’d have a solution by now if I spent the time writing this on thinking about it. Well, duh. Writing about not knowing is more fun, and easier, than thinking hard about it, see? Damn my lazy, easily-bored hide.

Posted by Oliver at 12:27 PM | Comments (2)

January 17, 2006

Beating spam with Movable Type 3.2

This is a somewhat detailed explanation of what worked for me in blocking spam in AWVC. The short version is that I tried installing a CAPTCHA, MT-SCode, which I couldn’t get working properly. Then I found MT-Keystrokes, which works brilliantly. So: Install the latter and you’ll be fine. The catch is that your site visitors will need to have Javascript enabled to leave comments.

The long version is contained in AWVC’s first ever extended entry!

Blogs, Comments, CAPTCHAs, and the utility thereof
Each brand of weblog software has software routines used to record comments. The routines are generally operated in exactly the same way across multiple installations of that weblog software. Scripted programs can be pointed at these specific routines to automatically log “comments” (i.e. crappy ads for crap). The routines are easy to locate as they’re generally described using plain text, easily parsed by a web script.

A CAPTCHA is designed to confirm the person entering a comment is an honest-to-God human. It uses an automatically generated image only a human could decipher (spam bots not being sufficiently advanced to decipher the generated image - yet, at any rate.

MT-SCode not being the most co-oerative of beasts
Lots of people seem capable of installing MT-SCode, and not having any problems with it. I ran into the problem described here. Currently there’s no explanation for the problem, but if it helps with future diagnosis, I’m running AWVC on the creaky BerkeleyDB back-end.

But SCode has other problems. The generated image (showing the code you need to type into the verification box) isn’t very attractive, and having to type anything at all into the box is an extra roadblock users leaving a casual comment might not be arsed working around. There are accessibility problems with CAPTCHAs too, which I’m not entirely comfortable with.

Finally, SCode requires Javascript. As far as I can tell the few regulars that I have all have Javascript enabled, so that’s okay, but it might not be for you.

I tried my damndest to get SCode working, but wasn’t really getting it going reliably. Then I stumbled across MT-Keystrokes.

Alternative Means of Detecting your Humanity
MT-Keystrokes also tries to confirm the person entering the text is a human, but does so without requiring the user to decipher an image. It does this by tying into a Javascript event handler - a piece of code that runs every time a user types something in a text box. Spam bots don’t come with built-in Javascript engines - yet - so they ignore the Javascript code and are consequently ignored by the blog software. The plugin still requires Javascript to be enabled, but doesn’t require the user to do anything more than they’d normally do when leaving a comment. MT-Keystrokes requires a bit more effort to install, but because it’s simpler than MT-SCode it should also be a bit more reliable.

The best part? AWVC = spam-free.

Addendum
Incidentally, while editing my MT configuration file, I screwed up the line-endings by saving the file in a Mac text editor. I thought I’d killed AWVC as whenever I tried to log in or leave a comment I got an error message saying Got an error: Bad ObjectDriver config. After some panic and then some calmer thinking, I resaved the file in a PC text editor and all was well. Google didn’t help at all though, leading me to believe I’d corrupted the database somehow.

Posted by Oliver at 09:24 PM | Comments (0)

February 18, 2005

Your US content filters will make jackeens of us all

What I have learned of the email filters where I work:

Clearly a quality product with perfectly ordered priorities.

Actually, that last one would make a good subtitle for Desperate Housewives, from what I can tell.

Posted by Oliver at 04:48 PM | Comments (0) | TrackBack

January 21, 2005

Ambition for the weekend

Get Monotone set up at home, use it while developing a new stylesheet for this site.

Er, and go out with friends, have drinks, enjoy the weekend and so forth.

(My sweetheart is away for the weekend. Should I not be plotting a wild series of drunken escapades instead of looking forward to getting obscure web stuff done?)

Edit: Got Monotone set up after hoursof Fink compiling away in the background. Got a fair bit of CSS done too, before getting stalled & realising I had no idea of what I wanted this place to look like! Still, I'm still of the (slightly better informed) opinion that Monotone is great. Monotone!

Posted by Oliver at 05:46 PM | Comments (0)

January 18, 2005

CROMA

I've not seen the language yet, so I'm still not totally clued in, but the winner of this year's Young Scientist won for developing a new Lisp dialect. Exciting obscure programming news! Too hard to explain! Late for dart! More later, hopefully...

Update: A handy Lemonodor post partly by the author himself. Yay. Now I wonder if I should have stuck with Lisp for longer. On the other hand, I am finding Haskell even more liberating...

Regardless, awesome stuff. Hats off to Patrick Collison.

Posted by Oliver at 05:41 PM | Comments (0)

January 17, 2005

Can I post to AWVC using Oddpost, the oh-so-super webmail client?

Yes! Yes I can!

That is all.

Posted by Oliver at 05:00 PM | Comments (0)

January 16, 2005

Something else I've learnt

... is that, in the US, it's possible to hang around a coffee house for seven months then release some fantastic software that makes you rich. Sigh.

This is very encouraging in an abstract way. "Encouraging" as there is some possiblity of success for this mode of operation. "Abstract" as it wasn't me getting rich.

Link courtesy of Daring Fireball.

Posted by Oliver at 08:59 PM | Comments (0)

What have I learned?

I've learnt that Movable Type doesn't support the word-processor style buttons for styling text in these posts when you're using Safari on Mac OS X, that's what I've learned.

And that I'm not sure if 'styling' is a real word.

Regardless, one demerit for MT.

Postscript: They work fine in Camino, Mac OS X's Firefox equivalent. Hmf. Also: if you're not using Firefox and you are using Windows, give Firefox a go. It's the internet without the fiddly bits.

Posted by Oliver at 08:13 PM | Comments (0)

January 14, 2005

Automating monotony

You'd think, for someone with a computer science postgrad, that I would have a good grip on how to, y'know, make software. Not to mention the various bits and pieces that make that process easier, like some system to keep track of different versions and changes made. An invisible archivist. CVS, for example. But, me being me, I'm not the type to download the most popular version and get started without thinking twice about it. Oh no. Instead, why not read about it, find out if it's really that good, and get a list of alternatives together? That way, rather than having something actually up and running, boredom will set in and I'll start doing something else. Right.

Then the excellent Rui Carmo of The Tao of Mac put up a great list of open source apps to 'watch' (or whatever the equivalent activity of keeping track of applications as they develop is called). On them is the intriguing Monotone CVS analogue (though it's peer-to-peer rather than client-server) and I'm sold. I'm a P2P kind of guy, after all. Plus it ties in with current project ideas.

Of course, when I say 'sold' I mean I downloaded and printed off their manual. But I've bound it and everything! Look at the shiny cover!

Posted by Oliver at 12:35 PM | Comments (0)