2011/12/04

Observer bias

Another way of putting it:
At its basic level, the Law of Fives is a practical demonstration that perception is intent-sensitive; that is, the perceiver's intentions inform the perception. To whatever extent one considers that perception is identical with reality, then, it has the corollary that reality is intent-sensitive.

2011/11/30

A startup

I realised a few months back that while I claim to be a programmer, I could also be called a serial-entrepreneur. I've founded 4 companies over the years (Educatic, ARTware, Awalé and Quaero). Me being an entrepreneur is kinda ironic, if you know me.

Anyway, the real goal of this post is to get a link to my latest companies brand new website. I'd like to brag about how awesome this website is, but it isn't awesome and prolly never will be. I didn't make it so don't blame me for the flash animation and canned newsroom sound.

But the thing is though, the product we sell really kicks ass. A fully configurable automagic document classification and document archiving intranet application. It can handle volumes of over 1 million documents a year. That's a lot of documents. One thing I realised a while back is that we didn't just write an archiving app, we wrote a tool to build an archiving app with. Which is both great and a pain because each install is so customised I have trouble keeping track.

It is noteworthy that this is the very first time one of my companies has even HAD a website. Which is another irony given that I developed websites for a living for over 10 years.

The URL again, for those that don't know how to the clicky-clicky: http://www.quaero.ca

(Full disclosure: I founded Quaero and yes this is a blatant attempt at seeding the search engines.)

2011/11/08

Sharp!

Inspired by a YouTube video, I pulled apart a old hard drive and turned it into a small, low powered grinder/sander.


I was wondering how to glue the sand paper to the platter. Them things are polished smooth. I was figuring sanding the platter and using epoxy. But it turns out that the centrifugal force at 5200 RPM flattens things out just find. Who would have thought!

One of the first things I did was grind myself a shiv. Because life is tough in the En-Aitch.


I then promptly dulled it cutting up some paper. See? Even the paper is tough in En-Aitch.

2011/09/14

Pretty lights

In a fit of weakness, I bought 2 silly USB mail lights. This are basically a PIC that talks USB on one side, and turns coloured leds on and off. They come with software that is supposed to check if you have mail and change colour depending on what's going on. Of course, the supplied software is Windows only and doesn't even work it seems.

Not that I care about a light that tells me if I have e-mail pending. But controling pretty lights from the computer? I'm all over that. Someone had already written a script in Python to control these things. I ported it to Perl because, well because I like Perl.

To use it, you must have Device::USB installed. And perl, of course.

http://pied.nu/Perl/setcolour

Doing setcolour will show you all devices installed

Doing setcolour 1294:1320 1 will set all mail devices to colour 1, which is blue on one of my devices, green on the other.

Doing setcolour 2-7 2 will set one mail device to colour 2, which is red on both my devices.

2011/09/12

UPS and power conditioning

If you have a server or any computer that is important, it needs an UPS. Something large enough for 5-10 minutes of power outage. But it is not enough to just plug the power into the UPS. You must also plug into UPS data port. And set up the software that will allow the computer to detect the power outage and shutdown before the battery runs out.

This is non-negotiable.

Not doing this risks you showing up Monday morning and not getting any work down while an admin drives 100 km to fix a problem.

And if you have any piece of important electronic equipment, you'll want a filter. And no the fuse on your power bar doesn't count.

2011/08/22

SSH tunneling for a small VPN

Here is a simple script that sets up a simple VPN between two networks using SSH tunneling. You must have root access to a computer on both networks. You must have 2 IP addresses for the remote network. The remote network is assumed to be /24. The script assumes that tun0 is available on both computers. If you don't understand this or you don't have this, you can't use this script.
#!/bin/bash


HOST=$1
LOCAL_IP=$2
REMOTE_IP=$3

eval $(ipcalc --network $LOCAL_IP/24)
if [[ "NETWORK=$NETWORK" != $(ipcalc --network $REMOTE_IP/24) ]] ; then
echo "Local IP ($LOCAL_IP) and remote IP ($REMOTE_IP) must be on the same network" >&2
exit 3
fi

ip route del $NETWORK/24 dev eth0 2>/dev/null
set -e

set -x
ssh -w 0:0 $HOST "
ip link set tun0 up
ip addr add $LOCAL_IP peer $REMOTE_IP/32 dev tun0
arp -sD $REMOTE_IP eth0 pub
echo 1 >/proc/sys/NETWORK/ipv4/ip_forward
echo OK
while true ; do sleep 3600 ; done
" | (
set +x
read OK;
echo "Connected to $HOST: $OK"
ip link set tun0 up
ip addr add $REMOTE_IP peer $LOCAL_IP/32 dev tun0
ip route add $NETWORK/24 via $REMOTE_IP dev tun0

iptables --append FORWARD --in-interface eth0 -j ACCEPT
iptables --table nat --append POSTROUTING --out-interface tun0 -j MASQUERADE
set +e
read -e -p 'Connected' K iptables --delete FORWARD --in-interface eth0 -j ACCEPT
iptables --table nat --delete POSTROUTING --out-interface tun0 -j MASQUERADE
echo "Use ^C to stop background ssh"
)

Note that the script has very little error checking beyond verifying that REMOTE_IP and LOCAL_IP are on the same /24.

The script is executed as vpn-ssh remote-host local-ip remote-ip. For example:
ssh my-client 192.168.100.130 192.168.100.205
192.168.100.130 is now an IP for the local computer. It may be connected to from the remote computer and anything on the remote network. If you set up your routing properly, other computers on the local network may also connect to the remote network also.

To create a tunnel ssh must run as root and must connect as root on the remote side. You should use have public/private keys set up, as allowing password login for root over ssh is a bad idea. Tunneling and root login are often deactivated by default, so you'll have to turn them on.

2011/08/19

Arduino on CentOS 5

So I bit the bullet and bought an Arduino UNO. The packaging should have a label on it "WARNING: BY OPENING THIS PACKAGE YOU RECOGNISE YOU WILL GET NO USEFUL WORK DONE TODAY."



All I wanted was to get one LED to flash. But that requires a avr-cpp-g++, which isn't available for CentOS 5. GRRRR!



So I wasted to much time getting the CentOS 6 SRPMs and getting them to compile. But you may fetch them from my psuedo-repo.

While time was a wasting, a kind soul on IRC sent me a hex file for bitlash which I managed to upload to the board. This allowed me to flash a few LEDs and get on with my work.

Writing code for the Arduino Uno in CentOS 5


RPMs will need from the psuedo-repo
avr-libc-1.7.0-1.noarch.rpm

avr-libc-docs-1.7.0-1.noarch.rpm
avr-binutils-2.20-2.x86_64.rpm
avrdude-5.10-1.x86_64.rpm
avr-gcc-4.5.0-2.x86_64.rpm
avr-gcc-c++-4.5.0-2.x86_64.rpm
gmp-4.3.1-7.x86_64.rpm
gmp-devel-4.3.1-7.x86_64.rpm
gmp-static-4.3.1-7.x86_64.rpm
libmpc-0.8-3.x86_64.rpm
libmpc-devel-0.8-3.x86_64.rpm
mpfr-2.4.1-6.x86_64.rpm
mpfr-devel-2.4.1-6.x86_64.rpm

You will also need arduino-0022.tar.gz, which I installed in /opt/arduino.

Now the IDE works, but it's in Java. Which hates me, hates Linux and I hate Java just as much, just for good measure I also hate IDEs. Working from two tutorials and with some slamming my head into the table, I got it working. The trick was massaging Johan's Makefile into something that worked. I also had to patch /opt/arduino/hardware/arduino/cores/arduino/wiring_private.h.

To start a new project, lets say "blink2"
mkdir blink2

cd blink2
wget http://awale.qc.ca/CentOS/rhel5/Makefile.arduino -O Makefile
wget http://awale.qc.ca/CentOS/rhel5/resetArduino.pl
touch blink2.pde

Now add your code to blink2.pde.

And here is my first Arduino program. It's a 6 LED chaser. It would be more, but I can only find 6 LEDs right now. Pins 13-9 are red, pin 8 is green. The green light stays on twice as long as the others.
#define DELAY 100


int state;
void setup(void) {
int pin;
state = 1;
for(pin=13; pin >=8; pin-- )
pinMode(pin, OUTPUT);
}

void set_state(void) {
int pin;
int mask = 1;
for(pin=13; pin >=8; pin-- ) {
digitalWrite( pin, (state & mask) );
mask <<= 1;
}

}

void loop(void) {

if( state == 1 ) {
state = 3;
}
else {
state = state << 1;
}
/* 0001 1000 = 18 */
/* 0011 0000 = 30 */
if( state == 0x60 ) { /* 0110 0000 = 60 */
state = 0x20;
set_state();
delay( DELAY*4 );
state = 1;
}
/* 0100 0010 = 42 */
else if( state == 0x42 ) {
state = 3;
}
set_state();

delay(DELAY);
}


Now compile and upload it:
make && sudo make upload

2011/07/21

Not Garbage Yet!

The three phases of things:
  1. Shiny and new and desirable;
  2. Garbage (very little survives);
  3. Old and desirable (aka Retro or Antique).

An example: the Pullman car was something a president wanted; North America reworked its railroads to accommodate it (and him). By now, most are destroyed. However, The New Brunswick Railway Museum has two. They also have a small shunting yard full of train cars, engines and cabooses that have survived the Garbage phase (in some cases just barely) and are moving into the Old and Desirable phase.

I ended up at the museum by accident; driving back to Shediac from the Hopewell Rocks, I saw a jet fighter plane parked by the side of the road. On a lark I turned the van around and drove pack to take pictures of it. My 14-year-old self wouldn't have forgiven me. But then Désirée claimed she wanted to see the trains. In fact she wanted to enter the trains. And so we did. And this brought back my 8 year old self and memories of the few train trips I made from Toronto to Montreal. There were no VIA Rail cars from the 70s, which I assume are still in the Garbage Phase, but some of the car seats from the 60s looked I bit like what I remember.

The real joy (for me) was in the large shed, where they had a Caboose we could enter. As a kid in North Hatley we used to watch the trains go by and wave at the man in the caboose. Cabooses (cabeese?) are now only a thing of memory (I had to explain to Dominique what a caboose was), but my inner 8-year-old-train-geek got a kick waving from the caboose at the passing kids. Or rather, my wife.

The next best thing was clambering around 3 locomotives, 2 diesel-electrics from the late 50s and a steam locomotive beast from 1912. And this is what is so awesome about this museum. I was afraid it would be all staring at immaculate restorations through plexiglass. Quite the contrary: we got to clamber on and around the locomotives and into the engineering rooms, sit on the beat-up seats, admire the different levels of tech in the controls from large brass levers all the way to 80s era scram switches and digital speedometers. Désirée could have shimmied into the boiler's furnace if her mother would have allowed her and her father could have cajoled her to do so. We pushed on the huge levers, pull the ropes, opened up the panels to see the turbines.

Were we supposed to do all this? No one was around to tell us not to; these are huge machines made to withstand years of hard work. We would have been hard pressed to break anything the engineers hadn't already.

Conclusion: Worth the price, worth a detour, would go again.

2011/07/20

Weighing the border

Years ago Susan used some mapping software to plot a route from North Hatley to (I think) New Brunswick. This was back when software came from a CD-ROM, not a web server. The software routed her through the USA. She added (I suspect) Rimouski to her itinerary as a way of by-passing the USA. It still routed her through Maine. As I remember, she then contacted tech support, who said they'd fix it in the next release. Remember, this was back when software was burned on CD-ROMs so they couldn't just tweak something and have it available next morning.

Because really, what you want is to give a border crossing a very high weight, so the AI will give it a low priority. CD-ROMs might also make you think of a time when crossing a border consisted of answering "yes, $DESTINATION, no, no" to a surly border guard. Nowadays it requires passports, finger printing and the possibility that you get shot when you go to reach for your glove compartment. So whatever the weight used to be, multiply it by 5. Or you could have a user configuration "USA border guards scare the hell out of me."

All this makes me wonder if there's someone at Google Maps who's job is to evaluate the relative difficulty of crossing various borders, updating the system as foreign policy deteriorates.

What brought this back to mind is that I'm currently IN Shediac, New Brunswick.

In semi-related news: I've finally mastered wireless connection setup in CentOS. Delete ifcfg-eth1 (in both /etc/sysconfig/network-scripts AND /etc/sysconfig/networking/devices), run nm-connection-editor, let the wizard to its work. NetworkManager stores its config in ~/.gconf/system/networking/connections. The WEP key is stored somewhere else. Yes, the place I'm staying uses WEP, which takes less then a minute to crack but more then a minute for the owner to write down for you.

2011/07/15

Pain

Something you don't see everyday:

# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb2[3](S) sdc2[2] sda2[4](F)
312367616 blocks level 5, 256k chunk, algorithm 2 [3/1] [__U]

unused devices:
Of course, this happens the day before I leave on a 2 week vacation.

2011/07/08

Fun with mysqldump

mysqldump makes for a quick and dirty way of backing up MySQL. Restore is trivial, if slow. However, it ties up the DB for the entire time it's running. Say you're like me and you have a table with 918,732,676 rows (yes, 9 hundred million rows). This means that the DB is tied up for 5 hours of dumping and 7 days for the restore. Clearly something better is needed.

However, before I work on integrating xtrabackup, I decided to see how slicing the dump with a LIMIT clause would work. mysqldump doesn't allow me to set LIMIT directly, however it does zero validation on the WHERE clause I can set. So:
(

mysqldump --opt DB --ignore-table BIGTABLE
mysqdump -NB --no-data DB BIGTABLE
MAX=$(mysql -NB DB -e 'select count(*) from BIGTABLE')
INC=$(( $MAX/1000 ))
seq -f '%.0f' 0 $INC $MAX | while read start ; do
mysqldump --compact --no-create-info DB BIGTABLE --where "1 LIMIT $start,$INC"
done
) > /my/backup.sql

This only works because mysqldump blindly tacks the WHERE clause onto it's select statement, giving us (roughly)
SELECT * FROM BIGTABLE WHERE 1 LIMIT 0,918732

This is a hack and a half: a- while it works now (Perconna 5.1.54) there's no guarantee it won't break at some point. But more importantly, b- this will still take a week to restore.

BTW, black-eyes to the idiots made %g the default seq format.

2011/06/27

Phishing

I just got called by someone from "Global Security Services." He had a very pleasant South Asian accent. He started with "I assume you are running the Microsoft Windows operating system." To which I answered "Of course not!" He quickly hung up.

Now, I'm going to be highly suspicious of anyone calling me long distance without caller ID info. The "Global Security mutter mutter" made me highly suspicious that this was part of a new phishing scam that's been going on. The goal is to have you install some "Microsoft Security product" which is of course malware.

Notice to readers and family members: They are calling people in Canada. Never ever install anything a cold-caller says to. Ideally stop using Windows at all. It's security is atrocious and the knowledge required to keep it secured is beyond most normal users.

2011/06/03

Alpine Linux

My router (pinky) used to boot uClibc Bering from a floppy. ucBering was really cool, but was getting ancient. The hardware was very noisy too. So I changed to less noisy hardware (JA Pinkerton), and run Alpine Linux. Alpine is a descendant of LEAF, which Bering was a variation of. It boots from CD and saves state to a USB key. Just have to remember to do lbu ci after any config change.

What's awesome: finally getting tcpdump on my router!
What's strange: full perl 5.12.3 on my router!

Alpine also include clamav, so you could use it to scan Windows computers for viruses. Kind of like these instructions.

2011/05/18

CentOS5 and a recent kernel.

CentOS 6 is just around the corner. But for those of us who have CentOS 5 deployed just about everywhere, the wait for a better kernel is annoying. While wasting time in some unsavoury corner of the Internet, I came across vserver, which is a clever way of sharing a kernel between separate OS instances. Think of it as VM writ small.

But even if you don't want or need multiple OSes, vserver installs a RHEL 6 kernel. And it works with CentOS 5. Say you need ATA TRIM? You got it. Having trouble getting WiFi working? Bingo. Card reader on your Laptop not working? It does now.

EDIT: the catch is that sound is no longer working. While this is OK for the laptop, it isn't for my desktop. Ah well.

However, I can TRIM corey's SSD by booting with the vserver kernel, then doing
dd if=/dev/zero of=/tmp/very-large

rm /tmp/very-large
The first command is going to fill any remaining space on the disk with zeros, so don't be doing anything important at the same time. When the disk fills up, it will exit and the second command will free the space.

You could also do the same thing with any boot CD that has TRIM support.

2011/05/17

Z8NA-D6 and lm-sensors

The ASUS Z9NA-D6 motherboard uses a w83795 chip for lm-sensors. Asus provides binary drivers, and then only for CentOS 5.4. On 5.6, you'll need these drivers. I've tested and they work on CentOS 5.6, 2.6.18-238.9.1.el5 x86_64. However, while sensors sees the chip, it doesn't manage to read the values. Must poke at it further.

Update: I finally got it working.

2011/05/04

Disk speed

I don't know if this makes sense. In fact, I'm pretty sure it doesn't. Writing 10 GB to a WD Green 2.0TB drive in a NexStar CX USB 3.0 enclosure connected to an ASUS Z8NA-D6C.
# time dd if=/dev/zero of=/dev/sdc2 bs=1024k count=20480

20480+0 records in
20480+0 records out
21474836480 bytes (21 GB) copied, 704.374 seconds, 30.5 MB/s

real 11m44.375s
user 0m0.029s
sys 0m21.517s


Same operation on an ASUS M2N-MX SE with "only" 4 GB of RAM:
# time dd if=/dev/zero of=/dev/sdb2 bs=1024k count=20480

20480+0 records in
20480+0 records out
21474836480 bytes (21 GB) copied, 847.95 seconds, 25.3 MB/s

real 14m7.969s
user 0m0.335s
sys 7m17.540s
Mind you, Xorg is running also, so that takes up RAM and CPU.

2011/04/01

loopback magic

First you used dd to grab the entire contents of a disk. Now you want to copy that disk to another one. Only the new disk isn't the exact same size as the old one, and probably doesn't have the same geometery. In which case you would be better off doing an rsync then dd to the new disk. The following trick will also work if you just want to read a partition.

First we need the offset of each partition:
#sfdisk -uB -l fulldump

last_lba(): I don't know how to handle files with mode 81a4
Disk fulldump: cannot get geometry

Disk fulldump: 17 cylinders, 255 heads, 63 sectors/track
Warning: The partition table looks like it was made
for C/H/S=*/224/56 (instead of 17/255/63).
For this listing I'll assume that geometry.
Units = blocks of 1024 bytes, counting from 0

Device Boot Start End #blocks Id System
fulldump1 28 144255 144228 83 Linux
fulldump2 144256 39080831 38936576 8e Linux LVM
fulldump3 0 - 0 0 Empty
fulldump4 0 - 0 0 Empty
We ignore the warning messages, because we see that the first partition starts at 28*1024=28672 bytes. So we can mount that easily.
# mount -o loop,offset=$((28*1024)) fulldump /mnt

# ls /mnt
config-2.6.18-164.el5 message
config-2.6.18-194.11.3.el5 symvers-2.6.18-164.el5.gz
grub/ symvers-2.6.18-194.11.3.el5.gz
initrd-2.6.18-164.el5.img System.map-2.6.18-164.el5
initrd-2.6.18-194.11.3.el5.img System.map-2.6.18-194.11.3.el5
initrd-2.6.18-194.11.3.el5-PG1.img t/
initrd-2.6.18-194.11.3.el5-PG2.img vmlinuz-2.6.18-164.el5
initrd-2.6.18-194.11.3.el5-SSD1.img vmlinuz-2.6.18-194.11.3.el5
lost+found/
I used $((28*1024)) because this way bash does the calculation for us.

2011/03/11

Rocky (again)

Installing foo2slx proved surprisingly painless. Of course, I did it the hard way by putting it in /opt rather /usr. Even then, I got the CUPS print page printed in colour in under 10 minutes.

I then did a little calculation. A complete set of toner carts are 220 $ (plus shipping) for 3000 pages. That's roughly 7.25 cents per page. Using Lexmark toner, roughly 15 cents per page. Refilling by the carts by-hand brings it down to 3 cents a page pus my wasted time. So no matter how you look at it, this is an expensive toy. I think I'l put a kitty jar next to the printer to collect money on each print.

2011/03/07

Rocky

A client gave me a brand new used printer. A brand new used colour laser Lexmark C500 network printer. I shall name it Rocky. Because it's a good deal heavier then Gunilla, my BW laser. In fact of all the computer's I've owned, the MIPS RISC/OS computer and maybe the IBM Model 90 where the only ones that weighed more then it.

It works. At least, the web server works and it will print up test pages. It being a first generation POS it uses some secret sacred line protocol that will require a bit of work to get running under Linux.

And 2 of the toner cards need cleaning. But that is just going to be fun.

But the really annoying part is that I'm going to have to spend a day or 3 doing colour calibration, because I'm that kind of compulsive that if I'm going to print out pictures, I want them to look good.

2011/03/02

Pretty


This is what I want my next office to look like.

2011/02/24

Google does it again

Impress me, that is. Look at this:
Google is good at this
Not only do they flag recipe as a special search type, but they allow me to refine my search by ingredient, cooking time and calories. OK, that last one is stupid and the list of ingredients they do allow me to exclude/include are a bit short, it's still impressive.

While on the subject of Google, take a look at this:
Google is good at this
See that subtle little blue bar above "Web"? What's more, they only waste 130 pixels before getting to search results.

Microsoft wastes 145 pixels, which is not bad considering how much more fluff they have.
Bing is a fast follower

And Yahoo! wastes 190 pixels. And has blinding blue links that I kinda, strangely enough.
Yahoo! flounders around without a map
Pixels are important. Everyone seems to have made the mistake of buying a wide screen LCD, vertical pixels are at a premium.

Trust the librarian

Daniel of course nails it right on the head.

2011/02/20

Nice one, Microsoft

For the last 2 weeks or so, I've been staring at and thinking about the UI to my new startup's flagship product. Beyond the Beyond pointed me towards a piece by the Windows Phone 7 metro design language. So I Googled up some examples. And I find this really beautiful website.

Now, if there's something I enjoy more then complaining about computers, it's complaining about Microsoft. Not only that, I've been staring at websites for the last +16 years. Rarely has a website design made me go "woah, yes!" Black/white/grey/orange? Liberal use of whitespace? Visible clutter approaching zero? WOAH! YES!

What's more, the videos of the Metro design language I've seen make it look really nice. I would call it what happens when you mix Helvetica, iOS and the minimalism of the 1972 Munich Olympic pictograms.

PS: I was going to post a link to Apple's iOS 4 page, but I had to spend a few minutes refusing all the cookies they wanted to set. Fuck 'em.

2011/02/08

Nice one Google

I might complain about computers a bit. OK, maybe I complain about computers a lot. But last night something jumped out at me that is Just Right. I was trying to find details of a Western Digital hard drive. I'd forgotten that they have wdc.com, as opposed to to the completely unused wd.com. Anyway, I googled "western digital" and noticed the following:

YES! That is so useful, it makes you wonder why they didn't have it before. Or did they and I only just noticed.

Also works: Asus, CPAN, boardcom, youtube. (Woah, 'you' returns youtube. OK, maybe not so strange, considering who owns youtube.)

I wonder what it takes to get the site-search treatment, because the following don't work: Linux, Perl, Apple, Wacom.

2011/02/03

ZeroMQ

Chatting away on #POE last night, someone mentioned ZeroMQ. I'd heard of it before, but this time it stuck. I read the book. And I'm hooked. I keep thinking of new ways to use it. And old problems that could be better solved with ZeroMQ. POEx::ZeroMQ might be in my near future.

2011/02/02

CentOS4 and gcc4

Say you are merrily compiling someone else's code on CentOS4 and you get something resembling the following:
query_response_time.cc: In function `void query_response_time::add_time_atomic(query_response_time::TimeCounter*, uint64)':

query_response_time.cc:160: error: `__sync_fetch_and_add' was not declared in this scope
query_response_time.cc: In member function `void query_response_time::time_collector::collect(uint64)':
query_response_time.cc:261: error: `__sync_fetch_and_add' was not declared in this scope
make[3]: *** [query_response_time.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory /usr/src/redhat/BUILD/Percona-Server/sql'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory /usr/src/redhat/BUILD/Percona-Server/sql'
make[1]: *** [all] Error 2
make[1]: Leaving directory /usr/src/redhat/BUILD/Percona-Server/sql'
make: *** [all-recursive] Error 1
error: Bad exit status from /var/tmp/rpm-tmp.49946 (%build)

You curse and swear. __sync_fetch_and_add is part of Intel's Itanium ABI and just plain isn't implemented in GCC 3, the default compiler in CentOS 4.

But the solution is easier then you think:
yum install gcc4 gcc4-c++

export CC=gcc4 CXX=c++4

OK, so maybe it's harder then that; you will probably have to add the following to your spec file:
BuildRequires: gcc4 gcc4-c++

%define cc_cmd ${CC:-gcc4}
%define cxx_cmd ${CCX:-g++4}

And replace any hardcoded reference to gcc or c++ with %{cc_cmd} or %{cxx_cmd}.

2011/01/21

Perl signals and fork aren't safe.

My very first Perl bug ever!

Long story short: there is a race condition between the safe signal handlers (which just update a flag) and pp_fork() invokes the system fork(). No, pp_fork() doesn't reset all the flags, so the signals could be dispatched in the child process, even if they were meant for the parent.

What boggles me is that this bug is easily over 10 years old. I find it hard to believe that no one noticed it before. Of course, it will take a while for a patch to make it into perl. And all the perls installed out their still have the bug.

The work around is to block signals, fork(), then unblock signals.

I'll write (or someone) IPC::SafeFork to do the above. But also draw attention to the issue.

Sphinx and daemontools

I'm moving the Big Document Warehouse Soon To Be Known As Quaero to using Sphinx for full-text searching. And of course I want to run searchd from daemontools. But searchd insists on backgrounding itself. Searching around I found people using fghack (which doesn't work) and --console (which isn't what is wanted).

However, peering into the source code to see if I could prevent it from backgrounding, I found just what I wanted: the undocumented --nodetach switch. Well, it has some documentation; there is a changelog entry that calls it a debug switch, which it isn't. Shame on you Sphinx-team!

Anyway, here is my daemontools run script:
#!/bin/bash


config=/opt/sphinx/etc/sphinx.cfg
servicename=sphinx

echo $(date "+%Y/%m/%d %H:%M:%S") $$ Sphinx searchd
exec setuidgid dw \
/opt/sphinx/bin/searchd --config $config --nodetach 2>&1 \
| /usr/bin/logger -p info -t $servicename


BTW, I have RPMs of Percona-Server (aka MySQL with a bunch of good patches) with SphinxSE.

2011/01/14

I need more RAM, Scotty!

Lookit this:
~ (root@corey:)# free
total used free shared buffers cached
Mem: 3913752 821824 3091928 0 38376 439640
-/+ buffers/cache: 343808 3569944
Swap: 0 0 0
4GB of RAM on Corey, boyee!

RAM is really cheap. I've been saying this for years. USD is also cheap these days. And I was finding Firefox really annoying at times. So I poked around Asus's site, discovered that Kingston claims that a M2N-MX SE can take 4GB of RAM. Out came the credit card. Thank you Newegg, thank you Purolator.

And yes, Firefox is subjectively much faster. Even though, as you can see above, I'm still using less then the 1 GB I had previously.

Or maybe it just stutters less. Or maybe it's the fresh reboot.

2011/01/13

Perl crumudgeon

Back last century, I read p5p-summaries, I participated in YAPC, I was active on #perl. I loved it when randal or tchrist would show us other, better, cleverer ways of doing things. I wrote some ambitious code and had some ambitious plans for all-dancing, all-singing frameworks. I one point I even looked into how to automagically build apps with Data::Flow.

Write the minimum of code and it would All Just Work.

Of course, I got over that. No framework can be all-dancing. There's a joke about a Clippy-a-like for an IDE: "I see you are writing a framework. Would you like me to a- erase this and Google for something that does what you want?"

But that's not all: I have a colocated server that runs some applications for clients. These apps were written for perl 5.004_05. I have no time nor want to get the running with a modern perl or mod_perl. But for years all the code I wrote had to with 5.004. And I insisted that POE would too.

And it now seems everyone is using Catalyst and Moose. And the shiny new things like "say" and "given/when." And perl 5.12. I JUST STARTED USING 5.8!

Of course "just" means a few years ago.

I think I've become a Perl curmudgeon, a more recent version of my associate Jean-Phillipp. When I first started working with him, he was using a modem to get to his customers, telnet and rlogin to communicate between servers, SCO and BASIC for everything. He's now accepted ssh (though I spotted an instance of rlogin last summer), gets me to install and sysadmin Linux. But still uses BASIC.

I guess I'm showing my years. "say" just looks ugly as a language construct; I have no problem typing "\n". Moose rubs me all wrong, despite it being very much aware of how much it is needed.

And while I've done a good deal of JavaScript recently, I haven't done any real AJAX, ie bidirectional. What they call comet.

In my defence, I've only really started 2 large projects in the last 6 years. These projects have taken most of my time. And with large projects, you should to stick with what the Way It Is Done or you get schizophrenic code. Not that my code isn't schizophrenic, but I've decided that just because you discovered some cool new way of doing something, you shouldn't use it the same day in an existing project. Magic is very hard to maintain.

What's more my toes are cold.

Now that I've identified the above, maybe I can change somethings and not be as hide-bound.