Transfer email and migrate accounts with YippieMove.

Archive

Author Archive

Good Django Celery Overview

October 14th, 2009

Happy stream of thoughts has a good overview over how RabbitMQ, Celery and Django work together to make distributed task processing easy and convenient in Django. The example described is for video processing.

RabbitMQ, Celery and Django

siker Programming , ,

Cool politics tool (for Americans)

October 11th, 2009

While I think avoidance is the best way to deal with US politics, what with all their internal spying and lack of constitutional backbone, here is a glimmer of light for those of you still hoping for improvement. The Truth-o-meter, a tool showing how well political promises are being kept. Wish we had a site like that in Sweden too (and then some tool to make the foolish masses actually care).

siker Site

Slashdot Slashdotted? Google Expunges Pirate Bay From Search Results story broken

October 3rd, 2009

Something weird happened to me this morning. I saw this article in my RSS feed:

Slashdot Story | Google Expunges Pirate Bay From Search Results

Barence writes “According to PC Pro, Google has removed all search result links to The Pirate Bay, the notorious file-sharing site. The move is a reaction to a takedown notice issued under the United States Digital Millennium Copyright Act (DMCA), although it’s unclear who filed the complaint. The ban isn’t particularly effective: The top result is now The Pirate Bay’s Wikipedia entry, which provides a prominent link to the site’s homepage. It’s also possible to search The Pirate Bay itself using Google’s site search.”

But when I tried to go read it I got the following error message:

The item you’re trying to view either does not exist, or is not viewable to you.

Weird. There’s not even a Google cache for it. I hope the article comes back alive later.

Update 1: Some people over at Slashdot noticed too and provided a link to an updated version of the real story on Cnet. Looks like Google reacted incorrectly to a DMCA takedown request, and Google has since added The Pirate Bay back in to their index.

The prompt reindexing may have been helped by a letter sent by Peter Sunde:

Peter Sunde-Kolmisoppi told Swedish newspaper Svenska Dagblated that The Pirate Bay’s attorney sent a letter to both Google and the companies that are suspected of being behind the allegations and demanded that the Pirate Bay be returned to Google’s index. The Pirate Bay accused Google of censoring a competitor and of stifling free expression, the paper reported.

The whole thing is a little curious when you think about it since Google lists plenty of torrent files without actually hosting any content, just like The Pirate Bay. It would have been a funny case of the pot calling the kettle black hadn’t it just been a mistake.

siker News , ,

Migrate Eventum to Redmine.

August 27th, 2009

I have migrated more stuff to the new Redmine setup. This time I pulled all issue data from an old and well used Eventum setup. I made some educated guesses about how the Eventum data was laid out and then hacked up the Redmine trac migration script until it worked for Eventum.

It’s really not a very pretty script but since I won’t be doing any more work on it I’ll release it here in the spirit of open source. Whether it works for you or not is anyone’s guess, but one thing is for sure: if it was just sitting on my hard drive it definitely would not.

Download: migrate_from_eventum.rake

See instructions in the beginning of the file.

siker Programming , , ,

A trick for Safari 4.0.3 table with border-radius and row background color leak.

August 22nd, 2009

While working on EmailServiceGuide I have been using the new border-radius property to get rounded corners without a ton of extra markup and images. It won’t work in Internet Explorer, but the idea is that people who run Internet Explorer are probably not that concerned about visuals anyhow.

Unfortunately the border-radius stuff is in development right now, so it doesn’t always work the way you expect it to. In particular I have this table with rounded corners and zebra pattern on the rows. In Safari the background color of the rows breaks through the rounded border of the table, sticking out sharply and concealing part of the table border. Neither overflow:hidden nor background-clip: border help.

What does help is to follow these instructions and make sure that the inner element with a background-color has a matching rounded border.

The sad thing with that is that in the table case you then have to use CSS to select and round off the top left, top right, bottom left and bottom right th or td elements which adds a lot of silly markup.

Here’s a little trick to cut down on that extra markup: make the zebra color on odd rows. Now the 0 row will have the table’s background color – which does get properly clipped to the table borders – and you know that the only possible place there could be trouble is if if the last row happens to be odd. So you can apply the rounded borders to the corner elements of the last row only and don’t have to do the first row!

Saves you several lines of CSS. : )

siker Site

Refactor Serializable Java Class

August 20th, 2009

Today I renamed and moved a class in a Java program. It was a Serializable class containing some preferences. As we are getting rid of it I renamed it from Preferences to LegacyPreferences, with the intention of starting a new Preferences class using a regular config file instead of serialization. Bad idea. Java refused to load serialized data into the new class for two reasons: one obvious and expected and one seriously braindamaged in true Java fashion.

The first problem was that the deserialization class could no longer find the class to deserialize to. No wonder since it was in a new package and had a new name. No problem. I subclassed ObjectInputStream and overrode resolveClass(ObjectStreamClass desc) to properly load the class from its new name and location.

That’s when Java freaked out with the following piece of brilliance:

local class name incompatible with stream class name X

Well, duh. Of course the name is different, that’s the point of a refactoring. What exactly were they trying to accomplish when they added this name check? The class has already been found, it’s interface is an exact match. The name of the class is irrelevant at this point.

I proceeded by overriding readClassDescriptor() with the intention to simply replace the name of the class with the new name when reading the stream. Java would never even realize the class used to have another name. But no: that method must return a java.io.ObjectStreamClass object, which you can’t instantiate or override unless you’re in the java.io package. And if you just grab the super.readClassDescriptor() instance you aren’t allowed to make any changes to it.

At this point I considered my favorite solution to Java damage. I’d like to call it “corrective Java surgery” – use reflection to force your way into the class and fix it. This is a very gratifying solution since you can undo the mistakes in Java and set things right. The drawback of course is that different versions of Java may require different corrective code.

That wasn’t necessary in this case since reading the source code of ObjectInputStream revealed a static method for creating ObjectStreamClasses: ObjectStreamClass.lookup. With that tool things fell into place very simply like so:

@Override
protected java.io.ObjectStreamClass readClassDescriptor() throws IOException ,ClassNotFoundException {
	ObjectStreamClass desc = super.readClassDescriptor();
	if (desc.getName().equals("com.trueship.base.Preferences")) {
		return ObjectStreamClass.lookup(LegacyPreferences.class);
	}
	return desc;
};

Hope that’ll help anyone else looking to rename and deserialize classes in Java.

siker Programming

SQLAlchemy 0.5.3 and 0.5.5 error: Set changed size during iteration

August 3rd, 2009

Update 1: See Mike Bayer’s comment below – looks like there’s a fix for this coming up in 0.5.6. Very responsive work by Mr. Bayer. Thanks!

YippieMove has been running into some spurious problems with SQLAlchemy. When upgrading Python from 2.5 to 2.6 the errors became a lot more frequent. The error is “Set changed size during iteration” and happens in all kinds of random code paths when using the ORM layer. Today I saw it happen when getting a result object from a query by index, and then again when iterating over the result of another query.

The end of the traceback looks something like this:


  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/dynamic.py", line 192, in __iter__
    sess = self.__session()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/dynamic.py", line 181, in __session
    sess.flush()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/session.py", line 1354, in flush
    self._flush(objects)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/session.py", line 1359, in _flush
    if (not self.identity_map.check_modified() and
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/identity.py", line 56, in check_modified
    for state in self._mutable_attrs:
RuntimeError: Set changed size during iteration

The code in question looks like this:


    for state in self._mutable_attrs:
        if state.modified:
            return True

The program is single threaded and it sure didn’t look like “state.modified” would cause the iterated over set to change. Weird. After snooping around for a while I found this post which suggests an async GC being the problem.

Sure enough the problem appears to have gone away when automatic GC is disabled. It’s not a nice workaround because the garbage collector in Python collects cyclic garbage. But it did solve the problem for now so here it is if anyone else needs it:

import gc
gc.disable()

Unless you want to be buried in garbage, make sure to collect it once in a while in a safe spot in your code using gc.collect().

Hopefully this will be fixed in a future version.

siker Programming ,

Migrate MoinMoinWiki to Redmine.

August 2nd, 2009

Today I switched a small wiki from MoinMoin to a new Redmine setup. I couldn’t find any existing scripts to convert the wiki pages over. For a moment I thought I could do MoinMoin to Trac and Trac to Redmine but I thought better of it. It’d be a lot of work and the wiki syntax would probably be completely mangled in the process.

Instead I hacked up Carl Nygard’s MediaWiki to Redmine script. It’s an awful hack really but it worked for the pages I needed, and it does preserve revision history.

  • Download the script: migrate_from_moinmoin.rake
  • Edit the source and enter your own email address instead of admin@example.com.
  • Place the file in lib/tasks/ in your Redmine installation.
  • Run the command with
    rake redmine:migrate_from_moinmoin RAILS_ENV="production"

  • Enter a project identifier.
  • Enter an absolute path to the data/pages folder of your MoinMoin install.

siker Programming , , , ,

Problem with jQuery 1.3 and :eq in a complex selector

August 1st, 2009

While trying to recreate this XPath as a jQuery selector I ran into some unexpected difficulties:

/html/body/table[3]/tbody/tr/td/table/tbody/tr

My first attempt to convert it looked something like this:

$("body > table:eq(2) > tbody > tr > td > table > tbody > tr")

This gave no results. I simplified it a little bit,

$("body > table:eq(2) tr tr")

Still no luck. After experimenting for a while it looked to me like :eq wasn’t playing well in this expression. The following worked:

$("body > table").eq(2).find('tr tr')

Weird.

siker Programming

Improved Cygwin Terminal

July 30th, 2009

The standard terminal in Cygwin is not very good. It can’t be made wider, you can’t select text normally using the mouse without first accessing the context menu and selecting ‘mark’, the default font is thick and ugly, etc. When you are used to the Mac OS X Terminal the Cygwin console is not fun.

Here’s the solution: puttycyg. It’s a modification of putty which allows it to act as a cygwin terminal in addition to the normal ssh and telnet functionality. Very cool!

Found it through this blog post. Thank you Andreas Hochsteger!

siker Programming