Storing chess positions efficiently in PostgreSQL
May 7th, 2008PostgreSQL has a wonderful feature which is called User-Defined types. It allows anyone to create a new datatype, along with the relevant operators, which are then managed almost natively by Postgres.
I decided to use this feature to manage chessboard positions in a more efficient manner than the usual ASCII storage which looks like “rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR”
I named this new type EPD, for “Extended Position Description”. I know that all the relevant data is not present (I shall typically store information like the active color, the casting availability, and a few other fields), but it didn’t sound like a bad choice for a name.
It allows to do some cool things like:
– Create a table with the epd type
chess=# CREATE TEMPORARY TABLE test_epd(my_epd epd);
CREATE TABLE– Insert a string - it gets automatically converted to a native format and only takes 32 bytes
chess=# INSERT INTO test_epd VALUES (’rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR’);
INSERT 0 1– And converted back into a string
chess=# SELECT * FROM test_epd;
my_epd
———————————————
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
(1 row)– What’s on A2 ?
chess=# SELECT epd_piece_at(my_epd, ‘a2′) FROM test_epd;
epd_piece_at
————–
n
(1 row)chess=#
The code is available here. The installation process is:
- Compile: make
- Install the .so: make install
- Configure postgresql: cat epd.sql | psql
Installing the VMWare tools with Debian Etch
March 17th, 2008Startup the guest Debian.
In VMWare, click on VM / Install VMWare Tools…
/dev/hdc must be unused !
Click on “Install”
VMWare will mount a virtual CD on your system. Copy VMwareTools-.tar.gz to your home directory
cd ~ && tar xzvf VMwareTools*
cd vmware-tools*
apt-get install gcc linux-headers-2.6-686
ln -s /usr/src/linux-headers-2.6.18-6-686 /usr/src/linux
cd /usr/src/linux
apt-get source kernel-image-2.6-686./vmware_install.pl
Answer [ENTER] to all questions - should work
Measuring a web server performance
March 4th, 2008This can obviously be done through the CLI using Apache Workbench.
Another nice interface is Apache JMeter.
Home to make a Samsung PVR HR-737 zone-free?
February 23rd, 2008This tricks only works if your DVD is in Zone 2.
- Empty the DVD tray
- Power off / Power On
- Wait for the boot
- Press 5 times 0 within 1 second
- Press “Repeat”
- Type: 57538
- You should see a “2″ in the upper left corner of the screen
- Quickly type 9
That’s it.
(Apparently if your DVD is Zone-2 then you should type 76884 instaed of 57538, but I couldn’t confirm it)
High-performance websites
January 28th, 2008… check Googletalk :)
How many CPUs are on my FreeBSD box?
January 19th, 2008Optimizing bulk inserts in MySQL
December 21st, 2007Link Here
How to make a Höher H088 DIVX/DVD zone-free?
September 6th, 2007MySQL logfiles analysis
September 4th, 2007Looking for a way to check your global MySQL performance, to identify missing indexes and other possible optimization points?
Today’s featured link should solve all your issues: mysqlsla.