Main

howto Archives

March 5, 2004

Porting PHP software from MySQL to PostgreSQL

While working on porting of LibData to PostgreSQL I created small toolkit which might be useful when converting application from MySQL to PostgreSQL.

Procedure is simple, first replace all calls for mysql_* functions to xx_* (so that program will call our wrapper functions -- there is script for that mysql2xx.sh) and then include one file which has wrapper from xx_* back to mysql_* or (with some more logic) to pg_*.

This toolkit is not complete wrapper for all mysql_* functions, but most projects don't use all functions anyway.

After conversion of database using my2pg.pl you have more-or-less working application on PostgreSQL. There are some problems: MySQL accepts '' (empty string) as null value for columns which are defined as integer, and that won't work in PostgreSQL. Right solution is to rewrite php code to use something like Pear DB with placeholders, and I will probably do that.

April 11, 2004

Kernel 2.6 hacking - Synaptics touchpad middle button

After upgrade of my laptop (HP Omnibook 6000) to kernel 2.6, my middle button on Synaptics touchpad remained dead. I tried with xev and no events got generated. So, I went hacking and after 6 hours I had patch which is available at my Linux page. And, it's just three lines.

What is the moral of this? If you do kernel development, better get payed by hour, not by line-of-code.

October 22, 2004

Bookmarklet to view cookies on page

This was so simple, that I'm not sure it deserves a whole blog entry. But, anyway. Up until now, I used LiveHTTPHeaders to view cookies, but latest version of Firefox (1.0 RC1) changed version of plugins and LiveHTTPHeaders doesn't work any more.

So, I wrote little bookmarklet to view cookies:

javascript:void(document.write('<html><pre>Cookie: '+unescape(document.cookie+'</pre></html>')));
Or just drag and drop this link to your browser. It displays cookies in format which is suitable for feeding into wget using --cookies=off --header="Cookie: ...." options.

November 16, 2004

Fed up with Firefox extensions that don't work with new versions?

Well... I am! Most extensions would work with Firefox 1.0 if authors declared maxVersion as 1.0. What can we do? Well, we can repack them using shell script and increase maxVersion to 1.0.

This script will by default increase maxVersion to 1.0, but you can also give any maxVersion as second parameter (for example 1.1 when it's available). First parameter is extension.xpi file. That file will be replaced with new file which has new extension version (I add +ver1fix to it). It shouldn't break extension update feature (if authors decide to fix maxVersion and increase version of extension).

This script comes without any warranty. If might break your Firefox if you try to install extension which really doesn't work (and I had few cases like that). On the other hand, it might save your day.

Update: fixed download link, again...

February 12, 2005

Passing over to the dark side

After about 10 years of using Linux on desktop, I did some Windows development today (no, I'm not reinstalling my desktop just yet). How to Win32::OLE under Linux? is new article on my site.

November 2, 2005

mod_ntlm and KeepAlive

I just spent three days of my life trying to make mod_ntlm work on one of two (presumably same) servers.

I have learned (head way) that you have to have KeepAlive On for mod_ntlm to work. So, I'm writing this post as a mental note and for other people who might find it using search engines.

You live and learn. Fun, right?

December 29, 2005

A day with FreeBSD (via qemu, that is)

In process of testing Fuse perl bindings before new release (which will support threading and hopefully FreeBSD) I need FreeBSD machine for testing. I opted to install it using qemu, without any graphic output (so that I can run it using ssh on remote machine).

It's a easy task, once you know how to do it. I used FreeBSD 6.0-RELEASE and installed it to disk image (using normal qemu with graphics). Then, I modified /boot/loader.conf to include:

console="comconsole"
This will redirect output from console to serial port. Nice, we don't need graphic any more!
Well, not so fast. We also need to install ssh server (so that we can actually login after boot).

Now, let's start qemu without graphic support and with redirect from localhost:4222 to ssh on our new FreeBSD machine:

qemu -hda hda -m 128 -net user -net nic -redir tcp:4222:10.0.2.15:22 -nographic -serial stdio -monitor stdio
You will get console output in terminal from which you started qemu (as well as boot messages) and after boot you can ssh -p 4222 localhost to login.

Quick edit of .ssh/config resulted in:

Host freebsd
	Hostname localhost
	HostKeyAlias freebsd.lan
	port 4222
Now, if you use ssh-copy-id logging in becomes simple ssh freebsd.

If you want to have semi-functional serial console, you can also change /etc/ttys line for serial terminal to:

ttyd0   "/usr/libexec/getty std.9600"   dialup  on secure
In line above dialup is terminal type. I tried cons25 and xterm but I still couldn't get vi to work well, so I prefer using ssh to connect to FreeBSD in qemu.

December 31, 2005

Debian sid x86_64 on qemu

As a new year present to all developers and users of qemu (and future users perhaps?) I have written how to install x86_64 Debian in qemu. It also includes bootable disk image, so you will be ready to boot your Debian x86_64 under qemu after a (shortish) download of 200+Mb image.

Happy new year!

April 17, 2006

Fix hr keyboard in X.org 7.0

As always, hr_US keyboard is broken (again) in X.org 7.0.
However, problem is easily solved this time (just one line diff), at least
under Debian:

--- /usr/share/X11/xkb/symbols/hr.orig	2006-04-14 16:44:19.000000000 +0200
+++ /usr/share/X11/xkb/symbols/hr	2006-04-14 16:44:36.000000000 +0200
@@ -10,6 +10,8 @@
 partial alphanumeric_keys 
 xkb_symbols "us" {
 
+    include "us"
+
     name[Group1]= "Croatia - US keyboard with Croatian letters";
 
     key  { [    any,    any,	backslash	        ] };

You should note that xkb files moved to /usr/share/X11/xkb/symbols
and that keyboard can be activated using:

$ setxkbmap hr us

Update: Ante Karamatic noted that same fix is already in
upstream code.
To be honest, fix was to include us and not latin symbols,
so that's also corrected in this post.

May 2, 2006

LVM: moving data from damaged PV to healthy one

This post is mix between rant and mental note:

When you move data off damaged PV (reported by smartd, thanks for it!) be sure that you do following thing:

  • boot in single user more
  • activate LVM (/etc/init.d/lvm start or similar)
  • don't mount logical volumes, because pvmove would block (without any explanation)
  • pvmove /dev/bad_pv /dev/good_pv
  • vgreduce vg_name /dev/bad_pv
I also found out that pvmove can, in fact, be restarted after reboot, but at which point it restarts is still a mystery to me.

August 5, 2006

svk support for vim

I'm happy svk/vim user now. Using few simple scripts which belong to your ~/.vim you will get diff view when you issue svk commit and syntax highlighted message. All of credits should go to Michael Scherer for his great svn-diff.vim and Dmitry Vasiliev for svn syntax highlight (included in vim 7) which I just modified for svk.

Update: fix download URL which broke when moving to MT, sorry...

September 9, 2006

How to import subversion into Google Code hosting

I guess, it's easy, once you know how to do it :-)

1. cache your user credentials

$ svn checkout https://webpac2.googlecode.com/svn/trunk/ webpac2 --username dpavlin 

2. install and init SVN::Mirror

$ cpanp i SVN::Mirror
$ export SVMREPOS=~/svm 
$ svm init google/ https://webpac2.googlecode.com/svn/
Committed revision 1.
$ svm sync google/
Syncing https://webpac2.googlecode.com/svn
Retrieving log information from 1 to 1
Committed revision 2 from revision 1.

3. create branch and import history

$ svn cp file://$SVMREPOS/google file://$SVMREPOS/initial_import -m "import of history"
Committed revision 3.
$ svn rm file://$SVMREPOS/initial_import/trunk -m "removed pre-created trunk"
Committed revision 4.
$ svnadmin dump ~/private/svn/webpac2/ --incremental | svnadmin load $SVMREPOS --parent-dir /initial_import

[... a lot of output ...]

4. Check if all revisions are here

$ svn info file://$SVMREPOS/initial_import/      
Path: initial_import
URL: file:///home/dpavlin/svm/initial_import
Repository Root: file:///home/dpavlin/svm/initial_import
Repository UUID: 07558da8-63fa-0310-ba24-9fe276d99e06
Revision: 663
Node Kind: directory
Last Changed Author: dpavlin
Last Changed Rev: 663
Last Changed Date: 2006-09-08 19:49:09 +0200 (Fri, 08 Sep 2006)

5. Find first revision to import (last changed in google branch+1)

$ svn info file://$SVMREPOS/google/
Path: google
URL: file:///home/dpavlin/svm/google
Repository Root: file:///home/dpavlin/svm
Repository UUID: 15ab016f-fa1c-0410-a7d3-f6d91a34b6aa
Revision: 670
Node Kind: directory
Last Changed Author: dpavlin
Last Changed Rev: 5
Last Changed Date: 2006-09-09 02:09:47 +0200 (Sat, 09 Sep 2006)

6. import other revisions (this will take forever)

$ perl -e 'print "$_\n" for ( 6 .. 670 )' | xargs -i svm mergeback google initial_import {}

7. watch progress with

$ svn log -v https://webpac2.googlecode.com/svn/

It sucks to loose timestamps, but at least you have your revisions...


Update: Lately I would reccomend to use SVN::Pusher to sync your changes. Downside is that SVN::Pusher won't work with file:/// URIs, but other that that it seems like a much easier approach. Usage goes something like this:

$ svn-pusher push -r 663:782 svn://svn.rot13.org/webpac2/ https://webpac2.googlecode.com/svn/

September 15, 2006

Apache auth_ldap and SSL

Update: Forget following post. It seems that openssl hangs when used like this (why?) and that much simplier solution is to just add:


AuthLDAPStartTLS on



So, you tried to change your AuthLDAPURL ldap://ldap.example.com to ldaps://ldap.example.com and got following message:


.htaccess: Secure LDAP (ldaps://) not supported. Rebuild auth_ldap

However, you don't want to rebuild auth_ldap today, so...

  1. create wrapper script like this: /usr/local/sbin/ldaps-tunnel

    #!/bin/sh
    exec /usr/bin/openssl s_client -connect ldap.example.com:636 -quiet 2>/dev/null


  2. edit your /etc/inetd.conf to include:

    ldap stream tcp nowait.9999 nobody /usr/sbin/tcpd /usr/local/sbin/ldaps-tunnel


  3. protect that only localhost can connect without ssl by adding following restriction to /etc/hosts.allow:

    ldaps-tunnel: LOCAL



October 21, 2006

Card reader on nc6120

I really needed to access smart card from my Nokia 6230i on HP/Compaq nc6120 so I spent some time making it work.

First, I noticed that kernel itself should have support for this reader, at least according to this info on sdhci. However, loading modules didn't show any dmesg output on my 104c:8034 device.

Then, I went to TI FlashMedia xx12/xx21 driver site, downloaded and installed modules and ho, here it is:


tifm_7xx1: sd card detected in socket 3
mmcblk0: mmc3:0001 IFX128 125440KiB
mmcblk0: p1

udev created card on next insert, and all I had to do was

$ mount /dev/mmcblk0p1 /mnt

Not bad, not bad.

November 15, 2006

Clean all HTTP cookies and kill session

This is really simple cookie killer which you can drag&drop to your bookmark bar to instantly erase all HTTP cookies which is very useful if you want to log off some site very quickly (or debug session handling :-)

This post is actually place-holder for it, because I find it really useful, and it might save you browser restart or two...

December 17, 2006

tar gotcha when migrating disk

Over the years, I have changed 2.5" hard-drives in laptop more often than I want to remember. Last one lasted only year and a half, which is noticably less than previous ones which managed to survive for two and half years at least.

But, this time, I didn't manage to find two 2.5" HD adapters for desktop PC, so I opted to use netcat and tar like this:

new$ nc -w 5 -l -p 8888 | tar xvfSp -
old$ tar cfvSp - / | nc new 8888

Can you see the touble here? (No, I'm not thinking about redundant S in one of tars -- hack, I'm not even sure it's redundant, man page didn't tell me anything useful).

If you couldn't guess, I didn't have completly same /etc/group and /etc/passwd on both machines. Life sucks. I should have used --numeric-owner for tar and all would be well, thus here is a blog post...

Update: if you are using framebuffer, leaving v flag will slow down transfer considerably because screen scrolling is slow. So, faster and correct alternative is:

new$ nc -w 5 -l -p 8888 | tar --numeric-owner -xSpf -
old$ tar --numeric-owner -cSpf - / | nc new 8888

December 23, 2006

Fuse for perl on FreeBSD

I'm maintainer of fuse perl binding for some time now. One of things that I'm somewhat proud is somewhat limited but working support for FreeBSD. Since I use FreeBSD only to test fuse bindings for perl, I tend to forget all little thigs which are different on it. So, here is a little reminder for my poor brain -- how to get my FreeBSD box up-to-date:

root@freebsd:/root# cvsup -L 2 /root/ports-supfile
root@freebsd:/# cd /usr/ports/sysutils/fusefs-libs
root@freebsd:/usr/ports/sysutils/fusefs-libs# make install
root@freebsd:/usr/ports/sysutils/fusefs-libs# cd /usr/ports/sysutils/fusefs-kmod/
root@freebsd:/usr/ports/sysutils/fusefs-kmod# make install

Currently bindings still compile against perl 5.8.7, and I'm compiling perl 5.8.8 with threading to give it a try. I think that I will really need to fix tests to run on FreeBSD first (help from BSD users would be greatly appreciated).

September 18, 2007

Optimized Link State Routing protocol

I have returned from YAXWE with very good impressions about mash networking. I did some reading and in theory I already knew how this works, but to see actual implementation of idea in form of Freifunk Firmware was both useful and impressive :-)

On the other hand, installing OLSR on Debian boxes is so easy that there is no excuse in becoming local mash node:

  1. Install packages
    $ apt-get install olsrd olsrd-plugins
    
  2. Put your card in adhoc mode

    This part might be specific to your card, but for my atheros card it's something like:

    $ wlanconfig ath1 create wlandev wifi0 wlanmode adhoc
    $ iwconfig ath1 essid olsr.example.com

    You should also probably run dhclient or ifconfig to setup your IP adress depending of configuration of your local mash network
  3. Change network interface in configuration

    $ vi /etc/olsrd/olsrd.conf


    Something like: Interface "ath1"
  4. Start it automatically

    $ vi /etc/default/olsrd

    Change line to START_OLSRD="YES"
  5. Start daemon

    $ /etc/init.d/olsrd start

    And that's it!. You are now part of mash network.

September 27, 2007

OpenMoko as a phone

For quite a long time I was complaining (in person) how nice and half-usable my OpenMoko is. However, thanks to few great hints I'm now make a dial out and dial in.

First, you will really want to install cu package. It contains old UUCP serial tool which will be much more unseful than you might think! Think of cu as cat for console.

Turn on your OpenMoko (while holding AUX button) and type following:

chown uucp:uucp /dev/ttyACM0 ; cu -l /dev/ttyACM0

You might try to just run cu as root, but it still doesn't work (for me) without chown first. If someone could say me to make this automatic, I would be grateful. So, dear lazyweb, I'm quite sure that there is some udev option for that, and if you know what, drop me a note. If not, this might become topic for another post.

Then, change boot parametars:

GTA01Bv4 # setenv bootargs_base rootfstype=jffs2 root=/dev/mtdblock4 console=tty0 loglevel=8
GTA01Bv4 # saveenv                
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
GTA01Bv4 # boot               

NAND read: device 0 offset 0x44000, size 0x1fc000
2080768 bytes read: OK
## Booting image at 32000000 ...
Image Name: OpenMoko Kernel Image Neo1973(GT
Created: 2007-08-31 11:29:10 UTC
Image Type: ARM Linux Kernel Image (gzip compressed)
Data Size: 1637653 Bytes = 1.6 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK

This will disable output on serial console which in interfering with gsmd that tries to open serial port to communicate with GSM part.

This is my journey so far... Now I have to wait for my poor old desktop to compile all packages to get freshest copies on my Neo...

October 2, 2007

X11 anti-aliasing slow?

My quest in finding faster X11 environment lead from WindowMaker to ion3, dwm and finally awesome. I would be very pleased with speed improvement if latest version of awesome didn't have xft support. Now I have to find and disable something I never needed in the first place, ehhh...

Have in mind that I do have laptops with more and more CPU power, so it's not that I use newer versions of software on some old crufty hardware (which I actually do from time to time, but that's not the point). Also, have in mind that I actually do like anti-aliased fonts but not in terminals and window managers.

What's wrong with anti-aliases fonts in terminals?

Glad you asked. Instead of trying to explain that (and failing), do a little test:

  • Pick any anti-aliased font in your terminal of choice
  • Execute find . in some directory with reasonable amount of files (home dir comes to mind)
  • Notice flickering on scroll? After a while it gets better (I guess that xfs cache some anti-alias information)
  • Now pick some fixed bitmap font and re-run find .
  • If you didn't notice difference in speed and flicker of scrolling you might be using terminal without xft support or bitmap font already.

But, anti-alias can't be that slow!

Nice try... Let's try another experiment. Open your ~/.fonts.conf and add something like:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <dir>~/.fonts</dir>
 <!-- bitmap fonts -->
 <dir>/usr/X11R6/lib/X11/fonts</dir>
 <match target="font" >
  <edit mode="assign" name="hinting" >
   <bool>true</bool>
  </edit>
 </match>
 <match target="font" >
  <edit mode="assign" name="hintstyle" >
   <const>hintmedium</const>
  </edit>
 </match>
 <!-- antialias tweaks -->
 <match target="font">
  <test compare="more" name="pixelsize" qual="any">
   <double>9</double>
  </test>
  <test compare="less" name="pixelsize" qual="any">
   <double>15</double>
  </test>
  <edit mode="assign" name="antialias">
   <bool>false</bool>
  </edit>
 </match>
 <match target="font">
  <test name="weight">
   <const>bold</const>
   <const>black</const>
  </test>
  <edit name="antialias" mode="assign">
   <bool>true</bool>
  </edit>
 </match>
 <match target="font">
   <edit name="rgba" mode="assign"><const>rgb</const></edit>
 </match>
</fontconfig>

This is my current configuration, you might want to skip rgba part if your LCD or CRT is different than mine...

Now re-try browsing in firefox (iceweasel, whatever). Do you notice something? Yes, it's faster. Even on dual core T2500. Isn't that somewhat strange?

To be quite honest, I'm running vesa graphic drivers. But, that's because my T60 has ATI Technologies Inc M52 [ATI Mobility Radeon X1300] card which isn't supported under current unstable Debian with any other driver (fglrx from Debian and xf86-video-avivo and/or xf86-video-radeonhd from upstream git). So, I have something to say about drivers also...

Is there any way to make anti-alias faster? Does compiling my own fontconfig might make a difference? I'll have to find out one day if there isn't any response to this post...

June 3, 2008

Subversion downgrade and permission errors

We had a double-disk failure on RAID5 array last week (yes, it does happen). One of things that got affected was our source code repository.


So, we reinstalled etch and installed subversion, did svnadmin verify on repository and all seemed well until we tried to commit using SVN DAV. Apache's error log was full of errors like this:


Could not create activity /svn/repo/!svn/act/9526cf2d-4893-4b35-a843-4c0f2d9f8bc6. [500, #0]
could not open dbm files. [500, #120022]
Can't open activity db: APR does not understand this error code [500, #120022]

But, permissions where correct! In utter desperation, I even tried chmod 777 on repository (kids, don't try this at home!) but it didn't help.


What did help was:


mkdir repo.new
svnadmin create repo.new
svnadmin dump repo | svnadmin load repo.new
mv repo repo.old
mv repo.new repo

Checking created repository with diff showed that it was indeed changed:

Binary files repo.old/dav/activities and repo/dav/activities differ
diff -rw repo.old/db/current repo/db/current
1c1
< 59 r9 1
---
> 62 ra 1
Only in repo/db/revprops: 60
Only in repo/db/revprops: 61
Only in repo/db/revprops: 62
diff -rw repo.old/db/revs/10 repo/db/revs/10
4c4
< id: aq.0.r10/17
---
> id: e1.0.r10/17
6c6
< pred: aq.0.r8/1443323
---
> pred: e1.0.r8/1443490
16c16
< dir b0.0.r8/1443476
---
> dir av.0.r8/1443643

and so on, for pages and pages.


I don't feel very good about changes, but repository was created with newer version from backports, and this time we used version from etch (thus downgrading from 1.4.6 to 1.4.2).


The whole point of this post is to help some random Google user with downgrade of subversion. So, here you have it!

About howto

This page contains an archive of all entries posted to Dobrica Pavlinušić's Weblog / Blog in the howto category. They are listed from oldest to newest.

hack-of-the-week is the previous category.

hr is the next category.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 4.1