Posts from monkey in the middle...
Posted by Samuel 751 days ago
Over the last days, I’ve been keeping myself busy with a sparkling new Rails app that (hopefully) will be of some public interest—at least among the Swedish-speaking public. The project is a webification of the Swedish Etymological Dictionary, which is a huge compilation of Swedish words along with a detailed description of the origin of each word.
Anyway, the app is relatively simple in its construction: The user uploads a Microsoft Word document (icky, I know, but that’s the format the linguists have been using), which is piped into the antiword utility to provide DocBook XML data. Which, in turn, is indexed and transferred to the database. The tricky part, however, is that the documents aren’t entirely consistent since a lot of different people have been transcribing the content, applying their own opinion on how the content should be formatted. That makes things tricky for the parser, and some documents need manual processing. Enter TinyMCE, a nice and user-friendly, cross-browser WYSIWYG editor that’s perfect for non-techy linguists!
But now to the problem: Since I’m such a web 2.0 junkie, the editor is enabled by clicking an “edit” button, which triggers some AJAX magic. It’s very intuitive, but it stretches the limits on what TinyMCE is meant to do. Originally designed to launch while the page is loaded and gracefully transfer its content to a form field when the page is unloaded, it has some slight problems adapting to pages where content and form fields pop out of nowhere after the page has been loaded.
Problem 1: I quickly found out that the editor content wasn’t sent back to the server when the form was submitted using AJAX. This was easily solved by triggering TinyMCE’s save routine (see this blog post for more on that).
Problem 2: (this was a really tricky one!) After some testing, I realized that the editor went crazy if I had loaded and unloaded the editor once. More specifically, it complained about this.getDoc() not having any properties. It turned out to be related to TinyMCE’s ID counter (a variable named tinyMCE.idCounter) not keeping track of the editor instances… or so I thought1.
It turned out to be even more subtle than that. Since the problem only seems to affect Gecko-based browsers (firefox, for instance), I thought there was something in Gecko that made TinyMCE go nuts. But it wasn’t really that simple. It turned out that the editor wasn’t loaded once, but twice—which explains the ID-related issue, since there were two editors hanging around instead of one. I had returned the AJAXed content in an .rjs template which was eval‘ed in the browser, and for some odd reason the eval() was done twice! Yay. To solve that, I had to refrain myself from using RJS, instead doing something like this:
link_to_remote 'Redigera',
:url => {:controller => 'document',
:action => 'edit_word',
:id => entry.id },
:update => "word_#{entry.id}",
:complete => "tinyMCE.execCommand('mceAddControl', true, 'entries_#{entry.id}')"
A simple hack… but at least it works! :)
1 see this thread on the TinyMCE forum
Posted by Samuel 775 days ago
Teaching programming can sometimes be a bit frustrating. After getting used to the flexible and fun methods a modern coder gets to work with, you suddenly find yourself stuck with a syllabus that ties everything to a programming methodology that smells an awful lot like the 1980s. At least that’s the case here in Sweden, and since bureaucracy is our national sport, we would have to dig through miles of paperwork for every deviation from the course plan.
Anyway, I decided to modernize things a bit and introduce some modern, agile programming techniques in our C-level programming course (which is the final course on the high school level). So far, I’ve introduced unit testing, version control (using SVN), the Trac bugtracker, and certain aspects of Extreme Programming (mostly the working in pairs thing and iterations). After studying the horrible syllabus, I still think I stick to it quite nicely.
This is a bit of an experiment from my side, and I have to evaluate it after this semester, but I think the students don’t mind it too much. At least one group has been very productive lately; I’ve been monitoring the RSS feed from their Trac installation and the commit messages are rolling by at a blazing speed! It’s going to be really interesting to see the results.
But my dream, of course, would be to turn everything into an all-Ruby course instead… but I get the feeling that it would be very far away since the course is originally designed for procedural Pascal programming :)
Posted by Samuel 800 days ago
Before anyone gets the wrong impression: Being a former PHP developer, I’m not a big fan but at least I respect the PHP philosophy of immediacy and keeping things light. But I simply can’t grasp how anyone would prefer this in favor of a real, structured framework:
The no-framework PHP MVC framework
I have to admit that it probably is more structured than the stuff most PHP developers are churning out, but why should the code necessarily have to look like a cat took a crap into your editor window while you were coding? OK, it’s lightweight, lean and all… but I still don’t get it.
Posted by Samuel 807 days ago
After months of delays, Minervaskolan’s new web site is now out in the open. Whew! The new site is powered by a content management system created by yours truly and it features just about everything you might expect, including RSS/Atom syndication, ajaxed live search functionality and a lot of other neat stuff. As usual, it’s a full-blown Rails app running on top of the awesome PostgreSQL database.
This was also the first time I used Switchtower to deploy an app. When it first was released, I didn’t give it any major attention as I was quite happy with the way I used to deploy things back then, but after about 15 minutes I came to realize how much I had missed. This thing is brilliant, easy to use, and I just love the way I can supply a single command and then lean back to watch the magic happen. The only problem so far is that Lighttpd sporadically refuses to start, forcing me to go in and do it manually every now and then. Any ideas on how to prevent that are very welcome :)
Posted by Samuel 835 days ago
After spending two hectic days struggling with the crashed server (among other things), I thought it could be a good idea to give a status report. The server is up and running with two fresh drives now, and with an even fresher and cleaner OpenBSD installation, and at least our intranet app is working the way it did before.
Recovering the lost data was a bit harder than I anticipated. I managed to transfer a lot by using dd to transfer the raw blocks onto a separate partition on a new drive, and after letting fsck repair the file system, all of the important data was in place. However, my old nemesis saw yet another chance to test my patience, as the fragile MyISAM tables had gone corrupt. It didn’t help to run myisamchk to repair them either (hey, it’s MySQL, what did you expect?), but I managed to get the bloody thing into a state where the tables could be sporadically dumped into plain SQL files. Of course, it wouldn’t let me dump all the tables at once, let alone dump all tables separately in one large operation; instead it would start pretending that the table files (the .MYI and .frm files that MyISAM tables consist of) didn’t exist after dumping about ten tables. The solution was simply to restart MySQL once that started to happen, which would buy me a few read operations until it went bananas again.
Since we had about fifty tables, the manual dumping took more time than I’d like to admit, and it was yet another reminder that MySQL should be shoved down our garbage bin as soon as possible. Also, the blog database still behaves this way despite the fact that I’ve recreated it from scratch using plain-text SQL files. I can get the blog to work for about five page loads, but after that it causes everything to blow up, including the intranet app. I still haven’t found out the best way of solving that, but I’m leaning towards a solution that includes a real database and the nifty mysql2pgsql script…
Posted by Samuel 837 days ago
This is a bit frustrating. When I was about to prepare some kind of backup routine (among other things) on our intranet server, which I migrated to OpenBSD some time ago, the hard drive crashed beyond repair. Naturally, Murphy’s law made the unrecoverable damage occur on the very same partition we kept most of the important stuff on, and the latest backups were more than two weeks old.
Can’t say I’m that surprised, though. We’ve been having severe power issues with blackouts and slight brownouts, and the disk has been badly tortured for quite some time. On the good side, we’ve bought two fresh new disks, with an UPS on the way too, and the patient is already being brushed up for prime time. Too bad this had to lead to data loss, but I’ll look into what I can do to minimize the damage once the system is starting to shape up. With some luck I can dd some data over to another disk, but I won’t make any promises.
Posted by Samuel 838 days ago
Following last week’s news about KM’s decision to leave the camera business, the whole Konica Minolta SLR user community has been a bit shocked and confused. The fact that very few people within KM itself knew about it before the announcement didn’t exactly make things more clear, and Sony didn’t reveal much either apart from that they are aiming towards a 20-25 percent market share. Anyhow, Sony seems to have gone public with their plans in an interview on a Japanese news site. An English translation can be found on the dpreview forum.
I still don’t know really what to think. The folks at Sony remain vague; the only thing that seems clear is that they are aiming at attracting advanced amateurs, but since KM’s current DSLR lineup can be said to fill that niche I still don’t know what to read into their statements. It also remains unclear what will happen to the existing lenses; it would be utterly stupid to ditch everything in favor of new optics, considering the huge amount of R&D put into the lineup over the last 20 years, but it would be tragic if the high-end lenses were to be scrapped. What remains clear, however, is that Sony will be making Sony products. What that means for a DSLR is unknown, but I hope the results won’t end up as weird and randomly designed as the Cybershot R1.
My decision remains the same, however… I’ll wait with any purchases until Sony releases anything, and if I don’t like what I see I’ll simply jump over to the second best (i.e. Nikon). Otherwise i so would have ruined myself with a 70-200 APO SSM lens this year, but I’m not in a hurry. Nikon makes nice telephoto lenses too, and it won’t be the end of the world if I’ll have to save a bit longer and buy a new camera body along with the corresponding Nikon telezoom. But they’ll have to pry my Dynax 5D out of my cold, dead fingers… along with the used 28mm prime I got for next to nothing on eBay, it’s such a lovely camera to use!
Posted by Samuel 838 days ago
OK, this is so cool. Zed Shaw, who wrote the Ruby SCGI adapter, Ruby/Odeum and a lot of other nifty things has brought the world yet another great lib. Meet Mongrel, a really fast, almost-pure-Ruby HTTP server! It’s still in its infancy, but it already runs circles around WEBrick, the web server included in Ruby’s standard library. And still it remains hassle-free and with a clean API, which is WEBrick’s main strength. The main difference seems to be that Mongrel is a lot more minimalistic (in a good way) and that the most hammered parts are written in C.
In all, it works quite well this far. I’ve tried it briefly, but it keeps giving sporadic error messages and dropped connections under OS X. But what the heck, it’s only been out for a few days and still is a 0.1 release, and I have no doubt it will be fixed shortly. It will be nice once it’s ready for production environments; I got a few medium-traffic Rails apps running that would benefit a lot from a hassle-free Ruby web server. Right now they are running lighttpd/fastcgi which is overkill, and since WEBrick is too slow, Mongrel would be the perfect solution!
Posted by Samuel 843 days ago
OK, this has to be the biggest disappointment of the year: Konica Minolta has decided to withdraw from the camera market completely, despite their recent success with their Dynax 5D and 7D SLRs. This also means that there will be no 7D-II or 9D at PMA, at least not from Konica Minolta. I definately didn’t expect this right now, but the fierce competition on the camera market was obviously too much for KM to handle.
But things aren’t really as horribly bad as they may seem, as the good stuff will be transferred to Sony instead. Sony and KM have been cooperating for quite some time, and judging from the press release, Sony brand DSLRs will be available starting this summer. It has previously been stated that the Sony cameras will incorporate the Anti-Shake technology and also use Minolta’s A-mount, and since most part of KM’s camera division simply gets another owner, I doubt things will change that much.
Also, I definately think this deal has positive sides too. Sony has a well-deserved reputation among professionals in other fields, they have enough resources not to fear short-term fiscal losses, and they will probably be better at handling the market than KM ever was. I just hope they will be wise enough to continue prioritizing ergonomics, build quality and cutting-edge features, otherwise my next camera will be a Nikon or a Pentax/Samsung instead…
Posted by Samuel 844 days ago
Yesterday evening, I was working on a better way to provide content indexing on the dictionary service I’m working on. The dictionary contains lots of archaic content with funny spelling, which the editors of the paper edition decided to indicate with parentheses. That’s OK for a paper book, since your brain has no problems parsing a string like “Burme(i)ster” (i.e. a family name with an alternate spelling). However, it definately causes problems in a searchable database-driven dictionary, since users looking for either “Burmester” or “Burmeister” would end up finding nothing.
So, I had to provide some kind of human-friendly indexing where a word with parentheses in it is indexed as two words; one for each spelling. Happily, I implemented it, only to realize that the dictionary contained words with two or even three parentheses (oh, the horror!). So, instead of only having to provide one alternate spelling, I had to deal with an exponentially increasing number of permutations. Argh!
Luckily, it didn’t take me too long before I came to think of a tree-based solution (those little fellows can be quite useful!). Thanks to recursion, the implementation is done in almost no code at all, and thanks to Ruby’s inherent beauty it still remains reasonably readable.
def permute(str, memo = [])
pattern = /\(.*?\)/
memo << str and return memo unless res = pattern.match(str)
permute str.sub(pattern, res.values_at(0).first[1..-2]), memo
permute str.sub(pattern, ''), memo
end
The implementation can be used the following way (for the Swedish word of “to snow”):
The only thing that bugs me a little is that Ruby’s MatchData class doesn’t provide an elegant way of accessing the part of the string that was matched by the expression… res.values_at(0).first feels a little too clunky for my taste. But I guess that’s the danger with Ruby, it really brings out the perfectionist in you :)
Posted by Samuel 851 days ago
OK, I know this tidbit is yesterday’s news by now:
Re-Introducing the Real Windows Vista
It’s fun because it’s true.
Posted by Samuel 853 days ago
I’ve spent the last hour or so stress-testing the public beta version of Adobe Lightroom (which can be downloaded here). It’s a product that has been under development for some time at Adobe, and today a mac-only beta has been released.
Although mostly a result of timing, the release of the public beta is probably a stab at Apple’s Aperture. The apps have obviously been developed in parallel, but I don’t see many other reasons for Adobe to release a mac-only public beta for free if they wouldn’t have that kind of competition from Apple themselves. But considering Aperture 1.0’s high price in conjunction with its hardware requirements and mediocre RAW quality, I doubt that many (hobby) photographers see Aperture as a serious alternative… yet.
Lightroom fills roughly the same kind of niche as Aperture, i.e. an all-in-one application with library management, RAW converter, slideshows and printing capability. It has a full-screen(ish) UI with nonstandard widgets, and the user is presented with four panels: Library, Develop, Slideshow and Print.
The Library panel is similar to most other photo library managers. To the right is a panel with options for quickly editing image parameters, which is normally done in the Develop panel. Images can either be viewed in loupe mode (one by one), compare mode or grid mode. Like in iPhoto, the thumbnail size in grid mode can be adjusted with a slider, but the scaling isn’t nearly as smooth.
The Develop panel is where the action happens. The adjustable parameters are just about the same as in Photoshop’s RAW importer, and judging from the output I guess a lot of that code is running behind the scenes. However, the entire panel is quite sluggish and it frequently “forgets” to update the image when a parameter is adjusted. Also, it’s not possible to control the zooming – you can either view the entire picture, shrunk to fit, or zoom in to full size. Nothing more, nothing less. Another annoying detail is the clunky control panel to the right, with different sections that are expanded or contracted when the title line is clicked. The entire thing feels very homegrown, and the Powerbook’s two-finger scrolling can’t be used – instead I had to use the teensy weensy scrollbar, which is a bit frustrating.
The slideshow panel works quite nicely, and provides plenty of options on what to show and not to show in the slideshow.
I haven’t tried to print from Lightroom yet, but the printing panel is snappy and very easy to use. Just pick your template of choice, select the image(s) you want, and print! It’s also very easy to adjust the page layout.
In all, I’m quite impressed by this public beta. It definately fills a niche, and the core functionality is great. The UI is sluggy and a bit inconsistent, and the Develop pane definately has its warts, but that’s probably going to be fixed in the final version. If the pricing is right I can definately see myself buying the final version, but the same applies to Aperture if Apple lowers the price and improves the RAW converter…
edit: Lightroom wasn’t developed at Macromedia as I initially wrote; it is an Adobe-only product that has been under development for the past four years. Thanks, Adrian!
Posted by Samuel 854 days ago
OK, I know I’m constantly ranting about MySQL, the piece of crap that happens to be the database of choice for the confused masses, but I can’t keep myself from doing that. Anyway, it seems to hate me just as much and never misses an opportunity to bite back, so I guess we’re even. I just thought I’d share yet another thing to my list of MySQL Moments™ and what to do when running into it.
The problem du jour is a really weird one, and I don’t know if it’s OpenBSD specific or if it occurs on other platforms. Judging from some quick research on google, I’m leaning towards the former. As with most MySQL errors, the error output is plain gibberish and documentation is almost nonexistant. What happens is that the following error message pops up:
(lengthy SQL query): Can't create/write to file '/var/tmp/#sql_2a19_0.MYI' (Errcode: 9)
Strangely, it mostly occurs when running Drupal, causing it to report about “user errrors”, just don’t ask me why. After some digging, I discovered that errcode 9 indicated a bad file descriptor, which could lead one to believe that the error was caused by some kind of file system nastiness. But that isn’t the case, instead the error was caused by MySQL itself as it tried to juggle more open files than it allowed itself to do. The most straightforward solution is to up the limit a bit, which can be done by editing the /etc/my.cnf file:
[mysqld]
open-files=1000
After doing that and restarting mysqld, everything started working nicely.
Posted by Samuel 859 days ago

...nice light, though :)
Posted by Samuel Kvarnbrink 929 days ago
As regular visitors may have noticed, I have finally switched theme on my blog. The new theme is called Dots and is created by, well, me! I’m actually very satisfied with the way it turned out; i aimed at creating something lean and functional, but with a certain funkyness. Whether or not I succeeded is an open question, but at least I like it – and it’s my weblog :)
Also, just to feed my competitive side a bit, I’ve submitted it to the Typo Theme Contest. Keep your fingers crossed!
Posted by Samuel Kvarnbrink 929 days ago
As regular visitors may have noticed, I have finally switched theme on my blog. The new theme is called Dots and is created by, well, me! I’m actually very satisfied with the way it turned out; i aimed at creating something lean and functional, but with a certain funkyness. Whether or not I succeeded is an open question, but at least I like it – and it’s my weblog :)
Also, just to feed my competitive side a bit, I’ve submitted it to the Typo Theme Contest. Keep your fingers crossed!
Posted by Samuel Kvarnbrink 933 days ago
After running on a medieval Typo installation for ages (I actually used Typo 1.6.8 and the latest version is 2.5.6), I finally got around to updating it. The beautiful admin interface works nicely, and blogging just got a bit more fun. It’s really starting to feel like a top-notch blogging tool now; if you ask me, it really kicks some WordPress butt.
The only problem right now is that the XMLRPC interface won’t work at all. That was a bit disappointing, but i’ll see what I can do to fix it unless someone else hasn’t already done it. Also, all comments just disappeared when I updated to the latest trunk, but that’s just the kind of thing one has to live with when running the bleeding-edge dev version :)
Posted by Samuel Kvarnbrink 933 days ago
After running on a medieval Typo installation for ages (I actually used Typo 1.6.8 and the latest version is 2.5.6), I finally got around to updating it. The beautiful admin interface works nicely, and blogging just got a bit more fun. It’s really starting to feel like a top-notch blogging tool now; if you ask me, it really kicks some WordPress butt.
The only problem right now is that the XMLRPC interface won’t work at all. That was a bit disappointing, but i’ll see what I can do to fix it unless someone else hasn’t already done it. Also, all comments just disappeared when I updated to the latest trunk, but that’s just the kind of thing one has to live with when running the bleeding-edge dev version :)
Posted by Samuel Kvarnbrink 944 days ago
It’s a fun new gadget. It’s built on Rails. And the people behind it even have the good taste of hiring a real illustrator to promote it.
Meet: Joyent!
But seriously, it seems fucking brilliant. A little magic box that you plug in, and boom – instant web-based collaboration, with e-mail, calendars, file sharing and whatnot. Personally, I don’t need one (even though the cute illustrations made me want one desperately before even finding out what it was), but I definately think it has potential. I mean, considering all the overpaid consultants I’ve ran into during my lifetime, it just has to succeed.
Posted by Samuel Kvarnbrink 944 days ago
It’s a fun new gadget. It’s built on Rails. And the people behind it even have the good taste of hiring a real illustrator to promote it.
Meet: Joyent!
But seriously, it seems fucking brilliant. A little magic box that you plug in, and boom – instant web-based collaboration, with e-mail, calendars, file sharing and whatnot. Personally, I don’t need one (even though the cute illustrations made me want one desperately before even finding out what it was), but I definately think it has potential. I mean, considering all the overpaid consultants I’ve ran into during my lifetime, it just has to succeed.