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