wiredfool

Archive for the 'Programming' Category

Postgresql

If you happen to be upgrading postgresql through a dump/reload cycle and get lots of errors like
“psql:db.dump:26268: invalid command \N”

It’s really simple. You probably haven’t loaded a schema yet, either by doing a data-only dump when you meant to do a full dump or by just forgetting to load the schema.

Also, at least in version 8.2, there’s a point in the schema dump where all the tables are in, but none of the constraints or indexes. That’s a real good place to split the file and do the data load.

No comments

EC2 Link Dump

These have been useful getting an ec2 instance running with some specially chosen software:

*
*
*
*

No comments

Files >> Memory

Sometimes, memory is slower than a file.

In Python, there are ‘file like objects’ that all respond to the same sorts of methods, open, read, write, close, that sort of thing. Some of them are files on disk, and some are memory buffers that are implement those methods. One would generally think that memory access is going to be faster than file access, but in the case of cStringIO and csv, it doesn’t appear to be the case.

I had a 4000 line csv file, about 700k worth, and another one that was 2x the size. Parsing that file took 10 seconds, the 8000 line file took 40 seconds. (amd64/ubuntu linux/python 2.4). Holy O(n^2) Batman! Since the CSV is just reading lines off a file (which implicitly advances the file pointer), I’m guessing that the cStringIO implementation of a file pointer is a numerical offset followed by traversing the string till it gets to the right spot. It’s not an actual pointer to a spot in memory.

So, I ripped out this code and used a temporary file (which on this machine, is going to be memory backed until it gets swapped out), and the times went to 2 and 4 seconds respectively. Almost certainly here, the file pointer is an actual pointer to a position in memory. Each movement is only a traversal of the size of the line, not the size of the file.

Big counterintuitive win here, by ignoring the buffering that Python provides and using the one that the OS provides.

No comments

WordPress

OMG WordPress 2.2. Upgraded to it a few evenings ago, and just tried to post for the first time. I’ve just lost 5 minutes of my life trying to get the last post to show multiple paragraphs instead of just mashing into one while using Safari to edit. Sometimes I miss <a href=’http://www.userland.com/manila’>Manila</a>. I got real tired of hosting it and keeping it running, as it was forked from Manila of 5 years ago. But dammit, it tended to actually do what I meant it to do most of the time.

Edit: That actually looked coherent in the visual editor. I’m going to leave it as a protest. WTF kind of weblogging software doesn’t accept typed in links?

Oh, and furthermore, it’s painfully slow getting to the admin pages in Safari if you’re not using the Webkit Nightlies. Painful. in. my. default. browser.

No comments

cURL and csv

When using cURL to upload raw csv over a HTTP post connection, the –data-binary option prevents munging the line endings out of existence. For some reason, even though files provided to the –data option are supposed to already be in their escaped form, it does another pass of something and returns line endings.

No comments

Master Stylesheet

Master Stylesheet: The Most Useful CSS Technique — this is one of those things that I’m posting with the intention of actually using someday,, but will probably lose and post again another couple of times before the next best thing comes along to make all the browsers work the same way with css.

Or something like that.

No comments

Towards more painless WordPress Upgrades

Or, I make subversion do what I should have done a long while ago.

The basic problem is that there are some updates that I’ve made to bits in this weblog to smooth over the rough bits from the manila migration — .htaccess mods and other little bits. The last security upgrade I did killed my modifications left a lot of old links hanging.

So, Subversion to the rescue.

The first step is to get the current bits into source control, and make the weblog directory source managed. There are a few ways to do that, but the best is to have it already done. The next best appears to be:

  • Extract your base WP archive, corresponding to what you installed in the first place. Do an svn import from there to get yourself a clean baseline, without any cache files or uploaded images. I’m choosing not to have images in my source control, I’ll probably regret that later.
  • Or, copy your live directory, delete the uploads and cache files, and import that. This might work better if you have a lot of themes or other cruft from a lot of upgrades.
  • Do an svn checkout into a new directory.
  • Rsync your current live wordpress directory on top of the the one you just checked out. This will bring in all of your changes in one big batch. Review them, and check them all in.
  • Make the directory where you just checked in your live wordpress install. (Rsync or renaming)

Now, when ever someone breaks into WordPress and they have a new point release, go into your wordpress directory and do a merge. We’re going to merge based on the wordpress subversion repository, get the differences between the patch level that’s installed and that which they just released.

svn merge http://svn.automattic.com/wordpress/tags/2.0.9/
       http://svn.automattic.com/wordpress/tags/2.0.10/ 
       .

(where you’re going to want that all on one line)

Everything should be a clean update or merge, if there’s a conflict then you’re going to have to manually resolve that before things work again. If it doesn’t look good, you can always revert to your repository version and fix elsewhere. If it looks good, then svn commit and you’re good till the next update.

No comments

Tableless forms

CSS2 – Tableless forms I’ve long used labels in forms, this should make it possible to cut a layer or twoof complexity out of the form display, yet still retaining the same visual structure.

No comments

Event.Behavior

Natural Language Event Programming for Prototype — More developments in the metaprogramming space for javascript.

No comments

Metaprogramming in Javascript

Mmmmm metaprogramming. Maybe it will make javascript suck less.

Metaprogramming / DSL JavaScript Presentation

No comments

« Previous PageNext Page »