January 28, 2011

Free php web stat analyzer

1. TraceWatch
2. BBClone

Both GPL and Free.

January 27, 2011

git, cgit and mini_httpd

 git allows very easy local installation. We need a easy way to view the local git repository. mini_httpd is a great local web server to use, and git web app can either be "gitweb" or "cgit".

I tried "gitweb" but couldn't get it to see my projects. But I got "cgit" to work well. Here is how:

1. download and compile cgit. very simple, just follow the README file.
2. change cgit Makefile, "CGIT_CONFIG = /yourpath/cgitrc", then "touch cgit.c" and "make" again. We do this because by default cgitrc is located at /etc/ and we want it local.
3. Create your cgitrc file from the example file. I use something like this:

cache-size=0
css=/cgit.css
enable-index-links=1
enable-log-filecount=1
enable-log-linecount=1
max-stats=quarter
root-title=My git repository
root-desc=Tracking my project development
root-readme=about.html
snapshots=tar.gz
mimetype.git=image/git
mimetype.html=text/html
mimetype.jpg=image/jpeg
mimetype.jpeg=image/jpeg
mimetype.pdf=application/pdf
mimetype.png=image/png
mimetype.svg=image/svg+xml
repo.url=linux
repo.path=/opt/gittest/.git
repo.desc=My project
repo.owner=me@me.com
repo.readme=info/web/about.html
repo.snapshots=tar.gz
repo.enable-log-linecount=0
repo.max-stats=month

4. start minihttpd and your are in business. :-)

January 26, 2011

Vim non greedy regular expression search

* (0 or more) greedy matching
\+ (1 or more) greedy matching
\{-} (0 or more) non-greedy matching
\{-n,} (at least n) non-greedy matching
 
http://blog.vinceliu.com/2008/02/non-greedy-regular-expression-matching.html 

CSS Positioning explained

http://www.barelyfitz.com/screencast/html-training/css/positioning/

Simple truth:

1. Use positon:relative in the outer box and then positoin:absolute in the inner box. This is very effective.

2. When using position:absolute with background image, make sure you explicitly specify "width" and "height", otherwise it won't work.

CSS and box shadow (blurred shadow)

All major browsers except IE (IE9 may support it) supports the CSS3 box shadow. So you need the javascript to do some tricks for IE. Here is the link. http://www.hintzmann.dk/testcenter/js/jquery/boxshadow/

January 24, 2011

Use Linux to control power outlet via USB

Much of information on this page is based the web page at here

1. buy EcoStrip , and Linksys USB2HUB4 USB 2.0 hub. This hub supports power control. Internally it uses NEC chipset.

2. Download hub-ctrl.c, OR download it at this site

3. Use lsusb utilities with -v option, you can inspect 'Hub Descriptor', such like:
Hub Descriptor:
   [...]
     wHubCharacteristic 0x0089
       Per-port power switching
       Per-port overcurrent protection
       Port indicators
   [...]

4.compile hub-ctrl.c with -lusb (you need to install libusb-dev if you don't have it)

5. run "sudo ./hub-ctrl" to list the possible hub that supports power control
Bus 002 Device 003: ID 0409:0058 NEC Corp. HighSpeed Hub
Bus 002 Device 002: ID 8087:0020
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
 
6.From above, you can see that my Linksys hub is located at Bus 2 Device 3. So I use the following command to turn the ecoStrip (which is plugged into the Linksys Hub port 1) power off:

sudo ./hub-ctrl -b 2 -d 3 -P 1 
 
And the following command to turn it on

sudo ./hub-ctrl -b 2 -d 3 -P 1 -p 1

January 21, 2011

transfer or populate sqlite table to another table

INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL1, COL4, COL7 FROM TABLE1

January 19, 2011

Use PHP to receive email

I use "sendmail". Other MTA should be similar.

1. Supposed you want php to receive emails destined to "support@example.com". Go to /etc/aliases and add a line:
     support: "|/usr/local/bin/getemail.php"

2. restart sendmail
3. go to /etc/smrsh, and create two symbolic link files:

 ln -s /usr/bin/php php
 ln -s /usr/local/bin/getemail.php getemail.php

These symbolic links basically tells sendmail you know these programs are safe for it to run

4. create your php script. A simple php script looks like this. Of course you should add your logic to it.
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
         $email .= fread($fd, 1024);
}
fclose($fd);

file_put_contents("/tmp/email.txt",$email);
die();

January 18, 2011

See which file is preventing you from mount read-only

In embedded systems, you can make your entire root file system read only (therefore preventing flash corruption) by doing:

mount -o remount,ro /

But sometimes this fails, because some files are being open as "writable". We need to find a way to identify these processes. lsof comes to rescue.
 
lsof +D / | awk $4~/w$/{print}

This commands list all open files recursively then uses an one-line awk script to find the lines that have files open for write. 

lsof is a really good friend. :-)

January 11, 2011

PHP PDF import and modification

There is a php library that allows importing a page from an existing PDF file, and then write data/graph on top of it. This essentially allows one to modify a pdf file.

The library is called FPDI (http://www.setasign.de/products/pdf-php-solutions/fpdi/about/). It uses the basic PDF library FPDF, or TCPDF (which is a fork of FPDF).

Seems useful. haven't tried it yet.

More: tried it yesterday and it works beautifully!! Use GSview32 to find the exact x/y of the place where you want to insert text/graph.

Another gem found.

January 10, 2011

https, TLS, SSL and multiple hosts

http://en.wikipedia.org/wiki/Server_Name_Indication

Unfortunately Windows XP with IE does not support this.