June 23, 2010

Image hard drive using dd

Update: If your drive have bad sectors, this method does not work well. I tried Clonezilla, and the result is as bad. Either my disk is very bad (but windows XP is running fine) or there is a better way to do this.

  1. Boot from the live cdrom distribution such as puppy linux.
  2. Switch to root.
  3. Make sure NO partitions are mounted from the source hard drive.
  4. (optional) Fill the drive empty space with 0
 # dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me
  1. Mount the external HD.
      # mount -t vfat /dev/sda1 /mnt/sda1
  2. Backup the drive.
      # dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c  > /mnt/sda1/hda.img.gz

    "dd" is the command to make a bit-by-bit copy of "if=/dev/hda" as the "Input File" to "of=/mnt/sda1/hda.img.gz" as the "Output File". Everything from the partition will go into an "Output File" named "hda.img.gz". "conv=sync,noerror" tells dd that if it can't read a block due to a read error, then it should at least write something to its output of the correct length. Even if your hard disk exhibits no errors, remember that dd will read every single block, including any blocks which the OS avoids using because it has marked them as bad. "bs=64K" is the block size of 64x1024 Bytes. Using this large of block size speeds up the copying process. The output of dd is then piped through gzip to compress it.

  3. To restore your system:
      # gunzip -c /mnt/sda1/hda.img.gz | dd of=/dev/hda conv=sync,noerror bs=64K
  4. Store extra information about the drive geometry necessary in order to interpret the partition table stored within the image. The most important of which is the cylinder size.
      # fdisk -l /dev/hda > /mnt/sda1/hda_fdisk.info

Notes:

One of the disadvantages of the dd method over software specifically designed for the job such as Ghost or partimage is that dd will store the entire partition, including blocks not currently used to store files, whereas the likes of Ghost understand the filesystem and don't store these unallocated blocks. The overhead isn't too bad as long as you compress the image and the unallocated blocks have low entropy. In general this will not be the case because the emtpy blocks contain random junk from bygone files. To rectify this, it's best to blank all unused blocks before making the image. After doing that, the unallocated blocks will contain mostly zeros and will therefore compress down to almost nothing.

Mount the partition, then create a file of zeros which fills the entire disk, then delete it again.

# dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me

source: http://www.linuxweblog.com/dd-image

June 21, 2010

mini_httpd and cgi

1. to specify the cgi pattern, you need to quote it and prepend with ./. For example, to make *.cgi files as cgi, use "./*.cgi"

June 15, 2010

The smallest XML parser in C?

I always love to see things done small and nice. If you are looking for a simple XML parser, I found ezXML to be the best. One C file, One H file. Compiles without warning. Just great. Here is the link:

http://ezxml.sourceforge.net/

Vim: search/replace to change cases

The following command will change all upper case words to lower case

:%s/[A-Z]/\L&/g

The list of all special commands:

Replacement part of the S&R has its own special characters which we are going to use to fix grammar:

#
Meaning
#
Meaning
&
the whole matched pattern
\L
the following characters are made lowercase
\0
the whole matched pattern
\U
the following characters are made uppercase
\1
the matched pattern in the first pair of \(\)
\E
end of \U and \L
\2
the matched pattern in the second pair of \(\)
\e
end of \U and \L
...
...
\r
split line in two at this point
\9
the matched pattern in the ninth pair of \(\)
\l
next character made lowercase
~
the previous substitute string
\u
next character made uppercase

June 11, 2010

QML Module and Property Access

If the main QML file includes modules from other files, it CANNOT see ids or variables defined in those files. You will have to use

"property alias myvar: localmod_id"

to expose localmod_id to your main QML file. variable exposure was documented, but entire object id exposure is not documented in other places.

Qt QML setContextProperty

In order to use a C++ Class function in your QML file, you can expose the class itself using setContextProperty("myvar",pointer_to_your_class_instance), then call myvar.func() in your QML file. However, there is a trick to get this to work.

In your class definition file, these functions have to been exposed as "public Q_SLOTS:", otherwise QML cannot see it.

June 10, 2010

Convert FLV to 3GP file

ffmpeg\bin\ffmpeg.exe -i input.flv -s qcif -vcodec h263 -acodec libfaac -ac 1 -ar 8000 -r 25 -ab 32000 -y outputfile.3gp

May 20, 2010

Good Free screen video capture / record, works under Vista

A good screen capture / record to video FREE program, directly from Microsoft, is called CommunityClips. It works for Windows XP and Vista. You an download it for FREE at
http://officelabs.com/projects/communityclips/Pages/Default.aspx

May 19, 2010

command line email client / mailer for gmail

Two programs:

1. SendEmail: http://caspian.dotconf.net/menu/Software/SendEmail/
2. smtp-cli: http://www.logix.cz/michal/devel/smtp-cli/

I tried SendEmail and it worked fine with gmail TLS SMTP.

The smtp-cli seems to have more features, which also means more complex. :-)

Both programs are written in Perl.

Brother MFC-495CW Inkjet Color

Brother MFC-495CW Inkjet Color

is a good PDF scanner. It scans to USB drive directly without PC.

It also has WiFi and Ethernet connection.

Add color to your linux console program

You can add color to your linux console print outs, such as usage.


#define CSI "\x1B\x5B"
main(){
printf("%s1;31m This is color text %s0m\n",CSI,CSI);
}

shell:
red text:
printf "\x1b\x5b1;31m Ignoring callcatcher \x1b\x5b0m\n";

green text:
printf "\x1b\x5b2;31m Ignoring callcatcher \x1b\x5b0m\n";

Details:
\x1B is Escape Char, \x5B is '['. They form the control string indicator.

1;31 are two commands
1 means bold color
31-37 are the colors

m: set display attributes command

0m: reset to normal display

color code list:
   Black      0;30       Dark Gray    1;30
  Red        0;31       Bold Red     1;31
  Green      0;32       Bold Green   1;32
  Yellow     0;33       Bold Yellow  1;33
  Blue       0;34       Bold Blue    1;34
  Purple     0;35       Bold Purple  1;35
  Cyan       0;36       Bold Cyan    1;36

  Light Gray 0;37       White        1;37


Other commands (from Wikipedia)
Code Effect Note
0 Reset / Normal all attributes off
1 Bright (increased intensity) or Bold
2 Faint (decreased intensity) not widely supported
3 Italic: on not widely supported. Sometimes treated as inverse.
4 Underline: Single
5 Blink: Slow less than 150 per minute
6 Blink: Rapid MS-DOS ANSI.SYS; 150 per minute or more
7 Image: Negative inverse or reverse; swap foreground and background
8 Conceal not widely supported
9 Crossed-out Characters legible, but marked for deletion.
10 Primary(default) font
11-19 n-th alternate font Select the n-th alternate font. 14 being the fourth alternate font, up to 19 being the 9th alternate font.
20 Fraktur
21 Underline: Double not widely supported
22 Normal color or intensity neither bright, bold nor faint
23 Not italic, not Fraktur
24 Underline: None not singly or doubly underlined
25 Blink: off
26 Reserved
27 Image: Positive
28 Reveal conceal off
29 Not crossed out
30–37 Set text color 3x, where x is from the color table below
38 Reserved
39 Default text color implementation defined (according to standard)
40–47 Set background color 4x, where x is from the color table below
48 Reserved
49 Default background color implementation defined (according to standard)
50 Reserved
51 Framed
52 Encircled
53 Overlined
54 Not framed or encircled
55 Not overlined
56-59 Reserved
60 ideogram underline or right side line
61 ideogram double underline or double line on the right side
62 ideogram overline or left side line
63 ideogram double overline or double line on the left side
64 ideogram stress marking
90–99 Set foreground color, high intensity aixterm (not in standard)
100–109 Set background color, high intensity aixterm (not in standard)

May 18, 2010

Unofficial Smartq V5/V7 Linux Development Guide

This is a backup of the original doc at: http://docs.google.com/View?id=ddtx8wkh_18g39zskpm

Unofficial Smartq V5/V7 Linux Development Guide


This guide describes how to compile your own linux kernel and how to create SmartqV firmware image for flashing the V5 or V7.
You need a working linux host for development, I'm using Ubuntu.

  1. Download the SmartqV SDK: http://rghost.net/980682
  2. Extract SDK to your working directory: tar -xvf SmartqV_SDK.tar.gz
  3. Install ARM toolchain:
    • Extract armv6_codesourcery.tar.bz2 file into /opt directory: tar –xvf armv6_codesourcery.tar.bz2
    • You should see /opt/armv6/... directory created.
  1. Go back to SmartqV_SDK directory and extract the kernel:
  1. Extract fw-utils:
    • tar -xvf fw-utils.tar.bz2
  1. Compiling the kernel:
    • cd mer-smartq-mer-smartq-kernel
  • Create default configuration: make SmartV7_defconfig for V7 or make SmartV5_defconfig for V5.
  • Run ./make_zImage_rootfs.sh and you can find a file named linux.rom under ../fw-utils directory.
  • make modules && make modules_install INSTALL_MOD_PATH=`pwd`/module-collection
    This pulls the generated modules into the ./module-collection directory, which can then be easily transferred with the kernel.
  1. Creating firmware image:
    • cd ../fw-utils
    • For V7: ./compress.v tcboot.V7 linux.rom 0 && mv SmartQV5 SmartQV7
    • For V5: ./compress.v tcboot.V5 linux.rom 0. The tcboot.V5 is not included in SDK, but you can extract it from official V5 image (see below).
    • This will create SmartQV5 or SmartQV7 firmware image.
  1. Copy the image to SD card and flash as usual.
  2. Notes: The firmware image will update only the bootloader and kernel image.
    You can create a full image including rootfs and homefs using compress.v utility.
    Use uncompress utility to extract newest bootloader from official firmware. Extracted files saved in /tmp directory.

Enjoy!

May 7, 2010

pause/resume a linux process

To pause:

kill -STOP pid

To Resume:

kill -CONT pid

Works perfectly.

May 4, 2010

Simple NAT for Internet sharing

You need a Linux machine (or virtual machine running Linux, or Colinux) to do this:


#enable routing
echo 1 > /proc/sys/net/ipv4/ip_forward

#flush iptable
iptables -t nat -F

#enable DNAT (also known as IP masquerading)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

#enable port forwarding
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 2401 -j DNAT --to 192.168.16.66:2401
iptables -t nat -A PREROUTING -i eth1 -p ALL --dport 82:88 -j DNAT --to 192.168.16.66:5000:5006

April 26, 2010

A good Javascript Calculator

http://cc.joensuu.fi/~tniemi/tools/calc.html

April 19, 2010

rpl_malloc error with configure

If you get a problem about an undefined reference to rpl_malloc, you probably need to do:
$ export ac_cv_func_malloc_0_nonnull=yes
before running ./configure ...

March 19, 2010

Serial Terminal Emulator on Linux/Ubuntu

Minicom, PuTTY, picocom, gtkterm, or cutecom

Console based:

1. minicom: the grand master and the one most people use
2. picocom: a mini minicom
3. some others not very well used such as: microcom, nanocom

GUI based:
1. cutecom (Qt based), able to dispaly and send HEX
2. gtkterm (GTK based, last release 2005), able to set serial port pin, and read pin status, and display and send HEX
3. PUTTY for linux (GTK based)



I recommend minicom, picocom and gtkterm.

March 7, 2010

Sichua Earthquake and Three Gorges Dam

From the following article, this Dam most likely have contributed to the Sichua earthquake. You use use Google Translate to read it in English.

http://www.zaobao.com/special/feature/pages/feature080706.shtml

  中国地震界制定了可能产生水库诱发地震的七项定性标准:①坝高于100米,库容大约10亿立方米;②库坝区有活动断裂;③库坝区为中新生代断陷 盆地或其边缘,近代升降活动明显;④深部存在重力梯度异常;⑤岩体深部张裂隙发育,透水性强;⑥库坝区曾有地震发生;⑦库坝区有温泉。上述七项,符合数越 多,该水库蓄水后诱发地震的可能性就越大。

  范晓说:“紫坪铺水库符合了上述七项标准中的前六项。”惟独没有的是,紫坪铺附近没有温泉。

  他根据本身进行的调查进一步指出,紫坪铺水库所处的地质结构位置相当令人担忧。“水库大坝下距龙门山主边界断裂在地表的出露迹线仅2公里,库尾淹没线上距龙门山中央断裂地表出露迹线仅约500米,库区还有与上述断裂平行的密集断层群通过。”


March 5, 2010

ctags for matlab on Windows

1. create a environment variable called HOME, and pointed it to whatever directory you like. On vista, I pointed to c:\Users\MYNAME

2. create file ctags.cnf under HOME directory you just pointed to with the following 3 lines:

--langdef=matlab
--langmap=matlab:.m
--regex-matlab=/^function([] A-Za-z0-9,_[]+=[ ]?|[ ]+)([^.(]+).*$/\2/f,function/

And done. Now you can run Ctags -R * on top of your project to create matlab tags file.

a short guide to enable samba server on Ubuntu

1. sudo apt-get install samba
2. sudo vi /etc/samba/smb.conf, look for [homes] and uncomment the following lines starting with [homes], change browserable to yes and readonly to no
[homes]
comment = Home Directories
browseable = yes

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no

3. give samba user a password by doing:
sudo  smbpasswd -a USERNAME

4. reload samba conf file by doing:
sudo /etc/init.d/samba reload
Done.

On Windows Explorer, type \\UBUNTU_IP_ADDRESS\USERNAME to see the share.