Sunday, November 1, 2009

removing the texture of old pictures with FFTs

Imagej ( has an awesome feature that allows you to perform an FFT on an image, edit it, and then do an inverse FFT. This is very useful for eliminating patterns from an image, such as the texture of old photographs.

Full size images for further comparison:

Monday, October 12, 2009

Booting to a raid volume using jfs

While upgrading an older debian server, I had to make some modifications to get the kernel booting. This shouldn't normally be necessary, but for some reason the hardware was not getting auto detected. I'm almost 100% sure I messed up some other step in order to require this. The system's root drive is raid1 and uses jfs. The following changes were done:

Added: /etc/initramfs-tools/modules:

modprobe raid1
modprobe md
modprobe jfs

mknod /dev/md2 b 9 2
mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
mdadm --assemble --scan

The above script must be chmod +x'd. I copied to it /etc/initramfs-tools/scripts/local-top/probe/local-premount/ just to make sure it ran.

Modified /usr/sbin/mkinitramfs in the #modutils section:
copy_exec /sbin/mdadm /sbin
copy_exec /sbin/fsck.jfs /sbin
mkdir -p "${DESTDIR}/etc/mdadm"
cp -a /etc/mdadm/mdadm.conf "${DESTDIR}/etc/mdadm/"

The above changes were done by booting into the rescue mode of a debian installer and mounting.

Tuesday, August 25, 2009

Installing Windows Server 2008 in VirtualBox

Today I installed a beta Windows Server 2008 onto a virtual machine on my Mac using VirtualBox. After some trial and error, the following settings seem to have allowed it to work:

OS Type: Windows 7 (64 bit)
Base Memory: 500 MB
Processors: 1
VT-x/AMD-V: Enabled
Nested Paging: Enabled

Video Memory: 12MB
3D Acceleration: Enabled

Thursday, August 20, 2009

Blocking spam from Yahoo! Personals

I get approximately 10 messages a day from Yahoo! Personals, which pass through spamassassin because they're DKIM signed. As far as I can tell, there's no way to opt out on Yahoo's end, so I had to resort to blocking every message with their telltale subject. Here's the rule:

header SUBJECT_YAHOO_PERSONALS Subject =~ /Dating 101: Reviving Your Relationship/i

Thursday, June 25, 2009

Debian Installation on Servers With Broadcom 5708/5709 NICs using the bnx2 driver

Installing Debian on a system with Broadcom network interfaces can be quite annoying because the firmware is no longer included. If you load the firmware onto a usb disk as suggested, you run into other problems when using scsi drives resulting in a system which requires hacking menu.lst after install to boot. This approach doesn't work if you're using iLO/DRAC/iDRAC to install as they only allow one remote media connection at a time.

An easy workaround is to modify your install iso to contain the drivers. Here's how:
  1. Download a newish Debian install iso.
  2. Mount the install iso:
    1. mkdir cdrom
    2. mount -o loop debian-testing-amd64-CD-1.iso cdrom
  3. Copy the files:
    1. mkdir isocopy
    2. cp -av cdrom isocopy
  4. Download the appropriate firmware package for your installation, such as
  5. Extract the drivers and copy into your new iso:
    1. dpkg-deb -x firmware-bnx2_0.16_all.deb firmware
    2. cp firmware/lib/firmware/* isocopy/cdrom
  6. Build a new iso:
    1. cd isocopy/cdrom
    2. mkisofs -o ../modified-debian.iso -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V disks .
  7. Done, let's look at our new iso:
    1. cd ..
    2. ls modified-debian.iso

You can now burn this iso to a CD or use it as virtual media.

There's one final step, which is getting the OS to see the firmware drivers.

Once booted to the new ISO, you need to immediately switch to another console and copy the files over before the installer looks for them:
  1. mkdir lib/firmware
  2. cp /cdrom/*.fw lib/firmware
After that's done, the Debian installer should be able to autoload the bnx2 driver without any problems.

Monday, June 15, 2009

php utf-8 chr() and ord() equivalents

As far as I can tell, PHP provides no built in methods of working with multi byte characters.

Here is a simple function for turning an integer value into a character:

function unichr($intval) {
return mb_convert_encoding(pack('n', $intval), 'UTF-8', 'UTF-16BE');

A uniord() function can be found in the comments of the PHP manual:

Monday, May 25, 2009

"This PDF document contains an Adobe XML form. Such files cannot be optimized."

To fix this problem:
  1. Save the document in LiveCycle with PDF compatibility
  2. Use the drop_xfa command with pdftk
This removes all of the LiveCycle data and makes the file compatible with Acrobat and other tools.

Tuesday, March 31, 2009

Some useful MegaCli commands/quick debian howto

MegaCli and MegaCli64 are the LSI utility used for Dell Perc 5 and other adapters isn't well documented. Here's some commands:

MegaCli -AdpEventLog -GetEvents -f logfile -aALL
What it does: Dump all events from the adapters event log to a file named logfile

MegaCli -PDList -aAll | less
What it does: Dump information about all Phsyical Disks (hence the PD), paged with less

MegaCli -LDInfo -LAll -aAll | less
What it does: Dump information about all Logical Disks on all adapters, paged with less

MegaCli -LdPdInfo -aAll | less
What it does: Dump information of all logical and physical disks on all known adapters

Currently these can be obtained from LSI at

You don't need to actually install the packages, both the MegaCli and MegaCli64 (64 bit build) are statically linked within. In order to access them in a non RPM environment, you can extract the files with the following command:
rpm2cpio MegaCli-1.01.39-0.i386.rpm | cpio -idmv
This will extra the MegaCli and MegaCli64 executables.
Alternately, you can try to convert the rpm to a .deb via alien.

Sunday, March 29, 2009

Video of morse code blinking

I modified a bike blinker to blink in morse code. Video of it in action is

Source is here.

Tuesday, March 10, 2009

One cause of "Fatal error: Exception thrown without a stack frame in Unknown on line 0"

"Fatal error: Exception thrown without a stack frame in Unknown on line 0" can be quite hard to debug.

php -r '
function a() {
$b = new DateTime("02/40/2009");
} '

Results in:
Fatal error: Exception thrown without a stack frame in Unknown on line 0

The problem is that PHP does not allow exceptions to be thrown in a shutdown function or anything called by a shutdown function. Initializing a DateTime object with an invalid date throws an exception, leading issues similar to above.

Friday, February 27, 2009

Fun with PHP implicit scoping on static calls

class a {
public $a = "yay!";

func call_b()

class b {
function b()
echo $this->a;

$a= new a();


This is because if you statically call a method that is not declared as static in PHP, it inherits the class scope of the caller. Note that if you had declared function b as a static method, you'd get a different behavior.

Wednesday, February 25, 2009

Apple Wireless Keyboard + Ubuntu Intrepid

I had some trouble pairing at first, but found this to work:
  1. Turn keyboard off
  2. Open up the new bluetooth device wizard
  3. Turn the on
  4. Select the keyboard
  5. Click Next
  6. While the wizard is waiting, enter 0000 and Enter on the keyboard
  7. Enter 0000 and Enter a second time.
The main issue seems to be that the OS doesn't prompt you at the correct time to enter the pairing password.

Tuesday, February 10, 2009

Fun with implict type conversions in PHP

PHP requires extreme care while programming. For example:
'1,234' * 1 == 1
0 == false
false == ''
0 == '0'
false != '0'