Category Archives: Web development

libdb2.so.1: cannot open shared object file: No such file or directory – … ibm_db.so

Got this error while deploying a Rails app on Nginx:

This means that the ibm_db adapter is installed, but it can’t find the DB2 libraries. The issue is that IBM_DB_HOME and some other environment variables are not set.

The best solution is to make sure all users have db2profile loaded. Edit /etc/profile and add:

You should now reload your profile (. /etc/profile) and restart Nginx.

This assumes that you already have IBM Data Server Driver installed under /opt/dsdriver.

Pixel-pushing in canvas

By way of avva (Russian), I was pointed to this excellent analysis of Notch’s 4kb Javascript/Canvas demo of flying through a 3d labyrinth:

Per the Hacker News discussion, this is not necessarily the way you should be using canvas for 3d — that’s what WebGL is for — but seeing what’s possible with relatively simple code and the basic web technologies is inspiring.

(Notch is the creator of Minecraft.)

TypeScript’s doomed embrace of JavaScript

Microsoft recently announced TypeScript. From what I can tell, it’s Javascript with optional types. The type annotation syntax is the same as in Adobe’s ActionScript and in the sadly defunct ECMAScript 4.

TypeScript also includes a new class syntax based on the one proposed in ECMAScript 6. I’m dubious about the addition of class-based features to Javascript. Javascript’s traditional strength is in prototypal inheritance and informal interfaces. I think there’s value in there being only one way to do things in a programming language.

As the Zen of Python puts it:

“There should be one– and preferably only one –obvious way to do it.”

And as Ruby’s designer Matsumoto describes the Principle of Least Astonishment:

“Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, ‘I was surprised by this feature of the language, so Ruby violates the principle of least surprise.’ Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise [sic]. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me.”

I’ve written Perl, and I’ve written C++. Both of them are kitchen sink languages that allow for every possible way of doing things. Per the above, this is not a good thing. For a discussion of the problems with C++, try the C++ Frequently Questioned Answers (FQA).

I think adding classes to Javascript would detract from the beauty of the language, or at least the beauty of JavaScript’s Good Parts. I would suggest that a much more useful and Javascript-esque enhancement would be not adding classes, but rather adding Go-style interfaces.

TypeScript is unlikely to become any more successful than Google’s Dart, thought to give Microsoft credit TypeScript is a lot more compatible with the existing Javascript infrastructure. The only post-Javascript success story that I’m aware of is CoffeeScript, and CoffeeScript’s strength is that it does not seek to replace Javascript.

(On a side note, I found out about TypeScript from Eric Lippert’s How do we ensure that method type inference terminates?)

How to access web console from Greasemonkey userscripts

Userscripts are helper Javascript programs that you can add to your browser to automate and optimize the web pages you visit. Greasemonkey is a Firefox extension to run userscripts. The web console is a tool built into Firefox and other browsers that can be helpful during userscript development.

How can you access the web console from Greasemonkey userscripts? First of all, you should not do this in production. However, logging to the web console can be a useful tool during development.

Here’s how you do it:

Bonus: How to access your userscript’s jQuery from the web console

Again, do not do this in production.

Userscript for faster deletion of MediaWiki spam

A couple weeks ago I posted a userscript that makes banning MediaWiki spammers easier by setting good defaults for the user ban form. Since then, I’ve had to ban a lot of spammers, so I thought I should remove another point of friction.

For some reason, MediaWiki chooses to not provide direct deletion links on the User Contributions page, so after banning a spammer you have to click through to each piece of spam before deleting it. This may have been an acceptable user experience in Web 1.0 days, but it’s a ridiculous set of hoops to jump through today.

My goal is to eventually make banning a spammer and deleting all the spam they’ve posted a one-click process. If there’s an existing solution for this, I’d love to hear about it.

Since I needed to do some DOM manipulation, I chose to use jQuery in the userscript. This was also a lot easier than I might have expected. Userscripts really are a very solid technology.

I passed the above through JSHint to make sure there’s nothing silly in it, but I haven’t consulted the jQuery style guide so it may not conform to the usual formatting.

The page delete links still lead to a standard confirmation form, so this doesn’t violate the RESTful practice of only using links for reading content rather than changing it.

Here’s a screenshot of what it adds to the user interface:

Userscript to make banning MediaWiki spammers easier

Somehow, I’ve come to be responsible for administering two MediaWiki-powered wikis. The main burden is having to ban spammers, which sometimes sign up in batches of 20 at a time.

To help with process, I’ve put together the following browser userscript. On Firefox, you can easily set it up using the Greasemonkey extension. Opera and Chrome have their own facilities.

The script basically makes the default values on the user ban form sane, so I can just click through without fiddling with dropdown and checkboxes. Obviously, the ban has to be permanent. Obviously, I don’t want spammers emailing anyone.

I’ve been hearing wonderful things about userscripts for years, but this is the first one I’ve put together for myself. It’s actually very easy to write these, assuming you know Javascript and have tools like Firefox’s Web Console and the Web Developer extension handy.

I’m planning to enhance it a little so that it handles the slightly different form for banning anonymous users, but I’m not sure if it makes sense to submit to any official repository. It helps with running small wikis that have open memberships, so there isn’t any one site I can identify it with. Obviously, it’s not suited for Wikipedia, as they have a very different set of problems.

Edit: Updated the script with better handling for banning anonymous users by IP address.