Thursday, August 28, 2008

another good reminder that lots of fun google search techniques are here

1. "define:" gives you the meaning of all words you write afterwards
2. "time" gives you the time of location
3. google search can be used as calculator with equation and end with '='
4. currency conversion by in
5. get the map of a city by map
6. get related search results using the "related:" keyword
7. use + and - in search term to plus a meaning or minus a meaning to the search term
8. type in a 3 digit and get the area where the 3 digit is used as phone number initial
9. quote search terms to get the exact result you want

Monday, August 25, 2008

in case i forgot it again, here is the link to wxWidgets installation guide for VC++2008

LINK

good linux habits

taken from IBM Linux help site

1. mkdir -p option allows multiple directory in different depth to be created all at once

e.g. mkdir -p good/{fun,happy/photos}
will create a directory good, which contains 2 directories fun and happy, and in happy a new directory photos

2. tar xvf -C unarchive without having to move the tar to the destination directory, giving the user an option to specify where the directory the tar will be unarchived

e.g. tar xvf /temp/a newarc.tar.gz

3. the && and || operator in command line are more advaned replacements for ;, which is the command separator in console. && checks if previous command have executed and returned 0, and only if it returned 0 the second command runs. || checks if the previous command returned non-zero, and only execute second command if non-zero return exit has been returned

e.g. cd /temp/a && mkdir b
e.g. cd /temp/a || mkdir -p /temp/a

4. It is generally a good idea to enclose variable calls in double quotation marks, unless you have a good reason not to. Similarly, if you are directly following a variable name with alphanumeric text, be sure also to enclose the variable name in curly braces ({}) to distinguish it from the surrounding text.

5. the escape sequence \ makes commands more clear

6. it's good habit to group commands using () in subshell or {} in current shell. this way all commands inside () or {} have their outputs grouped together for further use. make sure that there is a space between commands and {}

7. xargs is a powerful output format tool that can do many types of filtering

e.g. ls -l | xargs
combines all listed files into one line

e.g. ls | xargs file
lists all files and its file type

a caution that xargs can cause error when reading '_', which if placed in a single line cause xargs to ignore anything afterwards, xargs -e turns off the end of file string feature

8. grep -c does the same thing as grep | wc -l and is faster. but grep -c only count lines containing matching patterns. to count all matching patterns,even if a line contain more than 1, use grep -o | wc -l

grep -o cannot be used with -c at the same time

9. use awk instead of grep when possible. awk captures the line if word matches the key at the right index

e.g. ls -l | awk '$6 = "Dec"'
captures all lines with 6th word = Dec

10. grep doesn't have to work with cat because grep can take file names as arguments

e.g. time grep and tmp/a/longfile.txt
does the same as time cat tmp/a/longfile.txt | grep and

Wednesday, August 20, 2008

Turn Gmail into a to do list with Superstar

you can turn gmail into a to do list. first turn on the new google lab gmail feature: Super star, and turn on 3 stars: red, orange, green. 2) enter

l:^ss_sr OR l:^ss_so OR l:^ss_sg

into the search field and any emails with red, orange and green stars will be selected, and the selection is updated every search

keep the search command page and enter a quick link on the left side for this, call it "to do list"

---------------

on the other hand, VMWare has released a linux virtual machine Fushion 2.0 for Mac. should check it out

Tuesday, August 19, 2008

A brief intro to Linux Cache Structure

there are many algorithms for memory allocation, but none of them have a net gain of benefit, all makes a trade off. the basic memory allocation algorithms are heap allocation, which the kernel divides cache into blocks that fit to the requested size, and de-allocate them after use. the algorithm is efficient in cache usage, but causes significant fragmentation.

the buddy allocation combines blocks of cache together after deallocation if neighborhood memory blocks are also free. and it allocates memory by the best fit approach. this is better than heap, but require more processing.

the linux kernel uses SunOS cache allocation algorithm the "slab allocation". its basic structure looks like this:
the kernel memory cache is listed as a chain, it is then subdivided into slabs, catagorized into slab full, slab partial, slab empty, and each slab contains a page of memory, each page is composed of objects being allocated.

the idea is that kernel takes much longer time to initilize objects than to allocate and deallocate memory, using slab caching, kernel can reuse the previously allocated memory, without initialize it, for reuse.

full tutorial can be found here.

Tuesday, August 5, 2008

windows file system NTFS: bad bad baby

windows NTFS file system supports a feature that allows a file to contain multiple inodes, which was originally used to support Macintosh file system, is a bad idea. you can use this feature to create hidden files for other files that will never show up in windows explorer. you can even hide executable files this way and attach them to windows kernels and do very bad things.

an example to show you how:

1. create a file with any name, like example.txt
2. click Start + R, and type in that file name, for example, "notepad C:\example.txt:hidden.exe"
3. a new file that pretends to be the inode of example.txt has been created, and if you try to find that file example.txt:hidden.exe in your explorer, you can't find it. the inode file's size won't even appear in example.txt. so you can put a 1 GB file into example.txt and you won't even notice. in fact, the only way you can notice this hidden file is to move this file from NTFS to FAT

this multiple inode feature is only used to save a file's custom information, such as author and such, but it doesn't block any file from including additional inode files that arn't being used legally.

and for all those people who thinks Windows Vista is better, you better read the 10 page long deprecated features from Windows XP to Windows Vista. Some of those deprecated features are nice for security, but some are stupid.

Friday, August 1, 2008

linux booting process summary

just a summary of how linux boots up from the ground:

5 steps

1. PC loads BIOS from flash memory. BIOS sets up hardware configuration, and read from special registry to use a device as the booting device, usually the hard disk. if it is hard disk, it loads the first sector of 512 bytes into memory.

2. the 512 bytes contains executable code for boot loader, the first ~400 bytes are executable code, then follows with 64 bytes of 4 primary partition information, including starting sector, ending sector, size etc, and then a 2 byte magic code 0xAA55 as boot sector validity checker. It loads the chosen booting partition (and mark other partitions not booted) and loads the second part of the boot loader.

3. the second part of the boot loader reads the partition loads the file system of the volumn, and reads the bootloader entirely and prompt the user to load the kernel. it put kernel into memory and transfers control to the kernel

4. the kernel executes and creates the real root system, loads up modules to control the hardware etc, and starts the init process which is for user processies

5. the init initializes the user processies, this is where the terminal starts up, or the log screen starts up

4. the rest of the bootloader locates the