Category The Pensive

Looping through large and slow datasets in Ruby

I recently had the pleasure of needing to load 30’000 records from MongoDB and then performing slow and memory intensive processing on them. Basically you can imagine it as a database of videos and MongoDB was holding the metadata and other bits but the actual video files were on disk somewhere. My parsing involved loading…

Quick Tip: iOS and web graphics in Illustrator

I wanted to make a note of one of these things I keep forgetting in Adobe Illustrator. It is very simple, obvious and keeps me sane while drawing UI elements. Make sure “Align to Pixel Grid” is actually selected! That gets you out of so much trouble. Problem is, you need to keep an eye…

Rails migration of indexes

A small gotcha when changing indexes in a migration. To change an index one has to first remove it and then add it again. Removing an index is the tricky part. The documentation states: remove_index(table_name, index_name): Removes the index specified by index_name. This is not strictly true as it turns out. The docs should probably…

Nginx + WordPress caching that actually works

I spent a lot of time yesterday trying to enable WP Super Cache, and subsequently W3 Total Cache for this website. SInce none of the hits I got on Google did the trick I thought I’d post my working settings for page caching with W3 Total Cache. I went with this plugin mainly because it…

Why isset() in PHP can be misleading

I thought this was worth noting even though a comment on php.net explain it very well.

You can not rely on isset() for associative arrays unless you know for a fact you are checking an array.

Javascript variable definitions

The variable scope in javascript can still surprise me. This is a nice one I debugged today: A variable that is not defined by “var” have a global scope. This can be a real pain since the globalization is implicit and easy to forget. I forgot the “var” when writing a for loop and could…

Finding ordered position of a row in MySQL

This is slightly modified from something I found @ http://www.kirupa.com/forum/archive/index.php/t-263260.html Using high-score lists or similar you often have a large number of rows where you want to know who is in 7th place or how well is id:254 doing. This eliminates the slow looping in php of big result-sets by making a sub-query in MySQL.…

Duplicating a mysql database

This is another MySQL trick I keep coming back to. mysqldump -u root –password=pass db1 | mysql -u root –password=pass db2 found @ http://mywheel.net/blog/index.php/2006/01/05/mysql-duplicate-database-quick-tip/

Locating potential duplicate before switching collation in MySQL

When you need to switch a fields collation you can check if any existing data will conflict with this change. For example a keyword-field might contain data that is considered unique in one collation but not in another. The Swedish character ä is considered a unique character in swedish collation but in general collation it…

Copy files while preserving permissions

The unix cp command makes you the owner of the copied files. You can set flags but this is supposedly a more complete way to keep any attributes. mkdir /var/backup/michael cd /home/michael tar cf – . | (cd /var/backup/michael && tar xBfp -) found @ http://info.michael-simons.eu/2007/03/18/copy-directories-and-preserve-permissions/