August 30, 2011

simple telnet server by using socat

On server side:

./socat exec:'bash -li',pty,stderr,setsid  tcp-listen:8999,reuseaddr

On client side:

./socat tcp-connect:127.0.0.1:8999 file:`tty`,raw,echo=0

C, C++ source code tools to help you be productive

1. Source code beautifier: helps you with coding style compliance
  indent
  uncrustify

2. Static anylysis
  pc-lint/flexelint (needs $$)
  splint
  cpplint.py (google code)

3. bug finder
  cppcheck
  flawfinder
  uno

August 26, 2011

gitignore diff_exclude

A list of files usually should be ignored by git and diff when you generate a patch:


*.o
*.out
*.a
*.so
*.dll
*.swp
*.la
*.lo
*.swp
.gitignore
.depend
tags
*~
*.d
*.1
*.Po
*.Plo
*.log
*.status
*.dd
CVS

Makefile Automatic Variables


Here is a table of automatic variables:
$@
The file name of the target of the rule. If the target is an archive member, then ‘$@’ is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ‘$@’ is the name of whichever target caused the rule's recipe to be run.
$%
The target member name, when the target is an archive member. See Archives. For example, if the target is foo.a(bar.o) then ‘$%’ is bar.o and ‘$@’ is foo.a. ‘$%’ is empty when the target is not an archive member.
$<
The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (see Implicit Rules).
$?
The names of all the prerequisites that are newer than the target, with spaces between them. For prerequisites which are archive members, only the named member is used (see Archives).
$^
The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the named member is used (see Archives). A target has only one prerequisite on each other file it depends on, no matter how many times each file is listed as a prerequisite. So if you list a prerequisite more than once for a target, the value of $^ contains just one copy of the name. This list does not contain any of the order-only prerequisites; for those see the ‘$|’ variable, below.
$+
This is like ‘$^’, but prerequisites listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order.
$|
The names of all the order-only prerequisites, with spaces between them.
$*
The stem with which an implicit rule matches (see How Patterns Match). If the target is dir/a.foo.b and the target pattern is a.%.b then the stem is dir/foo. The stem is useful for constructing names of related files. In a static pattern rule, the stem is part of the file name that matched the ‘%’ in the target pattern. In an explicit rule, there is no stem; so ‘$*’ cannot be determined in that way. Instead, if the target name ends with a recognized suffix (see Old-Fashioned Suffix Rules), ‘$*’ is set to the target name minus the suffix. For example, if the target name is ‘foo.c’, then ‘$*’ is set to ‘foo’, since ‘.c’ is a suffix. GNU make does this bizarre thing only for compatibility with other implementations of make. You should generally avoid using ‘$*’ except in implicit rules or static pattern rules. If the target name in an explicit rule does not end with a recognized suffix, ‘$*’ is set to the empty string for that rule.
$?’ is useful even in explicit rules when you wish to operate on only the prerequisites that have changed. For example, suppose that an archive named lib is supposed to contain copies of several object files. This rule copies just the changed object files into the archive:
lib: foo.o bar.o lose.o win.o
             ar r lib $?
Of the variables listed above, four have values that are single file names, and three have values that are lists of file names. These seven have variants that get just the file's directory name or just the file name within the directory. The variant variables' names are formed by appending ‘D’ or ‘F’, respectively. These variants are semi-obsolete in GNU make since the functions dir and notdir can be used to get a similar effect (see Functions for File Names). Note, however, that the ‘D’ variants all omit the trailing slash which always appears in the output of the dir function. Here is a table of the variants:
$(@D)
The directory part of the file name of the target, with the trailing slash removed. If the value of ‘$@’ is dir/foo.o then ‘$(@D)’ is dir. This value is . if ‘$@’ does not contain a slash.
$(@F)
The file-within-directory part of the file name of the target. If the value of ‘$@’ is dir/foo.o then ‘$(@F)’ is foo.o. ‘$(@F)’ is equivalent to ‘$(notdir $@)’.
$(*D)
$(*F)
The directory part and the file-within-directory part of the stem; dir and foo in this example.
$(%D)
$(%F)
The directory part and the file-within-directory part of the target archive member name. This makes sense only for archive member targets of the form archive(member) and is useful only when member may contain a directory name. (See Archive Members as Targets.)
$(<D)
$(<F)
The directory part and the file-within-directory part of the first prerequisite.
$(^D)
$(^F)
Lists of the directory parts and the file-within-directory parts of all prerequisites.
$(+D)
$(+F)
Lists of the directory parts and the file-within-directory parts of all prerequisites, including multiple instances of duplicated prerequisites.
$(?D)
$(?F)
Lists of the directory parts and the file-within-directory parts of all prerequisites that are newer than the target.
Note that we use a special stylistic convention when we talk about these automatic variables; we write “the value of ‘$<’”, rather than “the variable <” as we would write for ordinary variables such as objects and CFLAGS. We think this convention looks more natural in this special case. Please do not assume it has a deep significance; ‘$<’ refers to the variable named < just as ‘$(CFLAGS)’ refers to the variable named CFLAGS. You could just as well use ‘$(<)’ in place of ‘$<’.

August 23, 2011

vim global command


The :global command is your friend - learn it well. It lets you run arbitrary :ex commands on every line that matches a regex. It abbreviates to :g.
To delete all lines that match "George Bush":
:g/George Bush/ d
The command that follows can have its own address/range prefix, which will be relative to the matched line. So to delete the 5th line after George Bush:
:g/George Bush/ .+5 d
To delete the DEBUG log entries:
:g/DEBUG/ .,+10 d
If you knew the stack trace was variable length but always ended at a blank line (or other regex):
:g/DEBUG/ .,/^$/ d
You can also execute a command on every line that does NOT match with :g!. e.g. to replace "Bush" with "Obama" on every line that does not contain the word "sucks":
 :g!/sucks/ s/Bush/Obama/
The default command is to print the line to the message window. e.g. to list every line marked TODO:
 :g/TODO
This is also useful for checking the regex matches the lines you expect before you do something destructive.
You can chain multiple commands using "|". e.g. to change Bush to Obama AND George to Barack on every line that does not contain "sucks":
 :g!/sucks/ s/Bush/Obama/g | s/George/Barack/g

vim global command


The :global command is your friend - learn it well. It lets you run arbitrary :ex commands on every line that matches a regex. It abbreviates to :g.
To delete all lines that match "George Bush":
:g/George Bush/ d
The command that follows can have its own address/range prefix, which will be relative to the matched line. So to delete the 5th line after George Bush:
:g/George Bush/ .+5 d
To delete the DEBUG log entries:
:g/DEBUG/ .,+10 d
If you knew the stack trace was variable length but always ended at a blank line (or other regex):
:g/DEBUG/ .,/^$/ d
You can also execute a command on every line that does NOT match with :g!. e.g. to replace "Bush" with "Obama" on every line that does not contain the word "sucks":
 :g!/sucks/ s/Bush/Obama/
The default command is to print the line to the message window. e.g. to list every line marked TODO:
 :g/TODO
This is also useful for checking the regex matches the lines you expect before you do something destructive.
You can chain multiple commands using "|". e.g. to change Bush to Obama AND George to Barack on every line that does not contain "sucks":
 :g!/sucks/ s/Bush/Obama/g | s/George/Barack/g

gcc default include path

this is how to find out the default include path:

method 1:


`gcc -print-prog-name=cc1` -v


method 2:

You can create a file that attempts to include a bogus system header. If you run gcc in verbose mode on such a source, it will list all the system include locations as it looks for the bogus header. $ echo "#include <bogus.h> int main(){}" > t.c; gcc -v t.c; rm t.c [..]
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i686-apple-darwin9/4.0.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
[..]
t.c:1:32: error: bogus.h: No such file or directory

August 19, 2011

FREE PHP IDE editors

1. aptana Studio
2. codeLobster
3. Komodo edit

August 8, 2011

Ubnt airos upgrade firmware

http://www.ubnt.com/wiki/Firmware_Recovery


hold reset pin while power up the device, then


tftp -i 192.168.1.20 put XS2.ar2316.v3.4-rc.4351.090504.2146.bin

August 4, 2011

virtualbox vboxheadless high cpu usage

If you are running RHEL / CentOS in virtualbox, and find that virtualbox uses high cpu even if the virtual machine is idling, it may be caused by the HZ=1000 timer interrupt issue in your linux kernel. The solution:

add divider=10 to the CentOS kernel parms in /boot/grub/grub.conf

August 2, 2011

Widows XP Remote Desktop IPv6

Windows XP Remote Desktop service does not listen on IPv6 addresses. Use the follow trick to fix it:

This command will do the trick.
netsh interface portproxy add v6tov4 listenport=3389 connectaddress=127.0.0.1 connectport=3389

After using it you'll be able to connect using a recent version of Remote Desktop Client over IPv6 to a WinXP/Win2k3 box.