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
August 30, 2011
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
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
*.o
*.out
*.a
*.so
*.dll
*.swp
*.la
*.lo
*.swp
.gitignore
.depend
tags
*~
*.d
*.1
*.Po
*.Plo
*.log
*.status
*.dd
CVS
August 25, 2011
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
makedoes this bizarre thing only for compatibility with other implementations ofmake. 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.
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.
<” 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":
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":
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":
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":
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:
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
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
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
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.
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.
July 28, 2011
Simulate unplug usb device on Linux (USB Reset)
http://cpansearch.perl.org/src/DPAVLIN/Biblio-RFID-0.03/examples/usbreset.c
/* usbreset -- send a USB port reset to a USB device */
/*
http://marc.info/?l=linux-usb-users&m=116827193506484&w=2
and needs mounted usbfs filesystem
sudo mount -t usbfs none /proc/bus/usb
There is a way to suspend a USB device. In order to use it,
you must have a kernel with CONFIG_PM_SYSFS_DEPRECATED turned on. To
suspend a device, do (as root):
echo -n 2 >/sys/bus/usb/devices/.../power/state
where the "..." is the ID for your device. To unsuspend, do the same
thing but with a "0" instead of the "2" above.
Note that this mechanism is slated to be removed from the kernel within
the next year. Hopefully some other mechanism will take its place.
> To reset a
> device?
Here's a program to do it. You invoke it as either
usbreset /proc/bus/usb/BBB/DDD
or
usbreset /dev/usbB.D
depending on how your system is set up, where BBB and DDD are the bus and
device address numbers.
Alan Stern
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
int main(int argc, char **argv)
{
const char *filename;
int fd;
int rc;
if (argc != 2) {
fprintf(stderr, "Usage: usbreset device-filename\n");
return 1;
}
filename = argv[1];
fd = open(filename, O_WRONLY);
if (fd < 0) {
perror("Error opening output file");
return 1;
}
printf("Resetting USB device %s\n", filename);
rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0) {
perror("Error in ioctl");
return 1;
}
printf("Reset successful\n");
close(fd);
return 0;
}
Tether Blackberry 9700 on Linux (Debian/Ubuntu)
With the fantastic open source software "barry", tethering to Blackberry ( I use 9700 and my carrier is AT&T) is very easy and straightforward. You don't need a Tethering plan, just the regular blackberry data plan.
Warning: be careful with your data usage once you are tethered.
My system is Debian 5.0.3. But this should work on all newer debians and reasonably new Ubuntus. Run all commands as "root":
1. Download and install barry for debian from the sourceforge website. You only need two files: libbarry0 and barry-utils. The files I use are:
barry-util_0.17.1-0_i386.deb libbarry0_0.17.1-0_i386.deb
2. For AT&T users:
cd /etc/ppp/peers
change the file 'barry-att_cingular' to comment out the following lines:
#novj
#noipdefault
3. run "pppd call barry-att_cingular" to get you connected.
Notes about routes:
If your computer already have a default gateway, pppd will not change/update it. In that case, make sure you delete your default gateway before running pppd, or you can manually add the default gw.
To stop the connection, just hit "Ctrl-C". Or, you can do "killall pppd" and wait for a few seconds for it to disconnect.
I use this in Vmware Player virtual machine with Debian 5.0.3 and it works great.
Warning: be careful with your data usage once you are tethered.
My system is Debian 5.0.3. But this should work on all newer debians and reasonably new Ubuntus. Run all commands as "root":
1. Download and install barry for debian from the sourceforge website. You only need two files: libbarry0 and barry-utils. The files I use are:
barry-util_0.17.1-0_i386.deb libbarry0_0.17.1-0_i386.deb
2. For AT&T users:
cd /etc/ppp/peers
change the file 'barry-att_cingular' to comment out the following lines:
#novj
#noipdefault
3. run "pppd call barry-att_cingular" to get you connected.
Notes about routes:
If your computer already have a default gateway, pppd will not change/update it. In that case, make sure you delete your default gateway before running pppd, or you can manually add the default gw.
To stop the connection, just hit "Ctrl-C". Or, you can do "killall pppd" and wait for a few seconds for it to disconnect.
I use this in Vmware Player virtual machine with Debian 5.0.3 and it works great.
July 20, 2011
Windows 2003 Server Remote Desktop Local Drive Map
I could not get the local drive map to work when I remote desktop to a windows 2003 server.
Turned out the the Windows 2003 server disabled the local drive map. So
Click Start, point to All Programs, point to Administrative Tools, and then click Terminal Services Configuration.
In the left pane, click Connections.
In the right pane, right-click RDP-tcp, and then click Properties.
Click around all the tabs, and make sure disk drive map is not disabled.
Turned out the the Windows 2003 server disabled the local drive map. So
July 17, 2011
airos persistent directory
AirOS allow users to add scripts in the /etc/persistent directory of Ubiquiti device.
These scripts can modify configuration by starting additional services and more.
The standard scripts are:
These scripts can modify configuration by starting additional services and more.
The standard scripts are:
/etc/persistent/rc.prestart /etc/persistent/rc.poststart /etc/persistent/rc.prestop /etc/persistent/rc.poststopThey are called before and after the standard boot and shutdown scripts start or stop services...
Add static route via script
- Reboot devices to clean all static routes and access via SSH/Telnet to AirOS device
- Create a script /etc/persistent/rc.poststart and write here commands to add static route
- Make sure that /etc/persistent/rc.poststart are executable
- Check if your script work fine running the command line: ./etc/persistent/rc.poststart
note: the command now start with a "dot" = run the script! - Run the command: cfgmtd -w -p /etc/ to make persistent
- Reboot and verify that all it's working...
July 16, 2011
openwrt make targets
Useful_Trunk_Rebuild_Make_Targets
These were culled from IRC logs at irc.freenode.net on #wgt634u . The comments may not be correct. If so, please fix them. This page was put together to help with build problems related to dirty source trees.
- make package/base-files-clean target/linux-clean target/lzma-clean target/utils-clean
- good general cleaning and doesn't rebuild toolchain
- clobbers certain changes you may have made to files in 'root' - (i.e. is it incompatible with WGT634U_USB_root building?)
- make target/linux-clean
- cleans kernel
- make clean
- duh, calls 'make dirclean'
- make toolchain/uClibc-clean
- clean uClibc only
- make package/base-files-clean
- always run before rebuild?
- DANGER - remove package and unpacks the source archive again
- aka: make package/package_name-clean (ie: make package/jpeg-clean)
- make package/package name-rebuild
- recompile the package after you make changes
- if this still does a make clean (ie: deletes everything, including your changes) add this to your package/whatever/Makefile:
I can't seem to get the above to look right, so just remember to indent the rm with a tab.
- make package/clean
- cleans all packages, not always required
- make target/clean
- ?
- for specific packages, e.g. courtesy of frop
- ...well, if there's a new version of madwifi (from svn)... 'make package/madwifi-clean'
- make target/install
- rebuilds install image (and kernel too?)
- make (any command) world
- runs that command, and recompile (same as "make (command); make" (i think))
- confirmed - yes, make takes multiple targets on the command line. Be careful when you type commands - if you miss a "-" and type make package/jpeg clean instead of make package/jpeg-clean it'll delete everything as it does the clean after a make package/jpeg. MUCH DIFFERENT!
July 14, 2011
sqlite 3 string to integer conversion, similar to C function atoi
In sqlite3, if you have a column defined as string, but you want to use it as integer when doing comparison, you can do the following to convert it.
CAST(expr AS type)
For example: you have a column named "version", and you stored value "11" in it. Now you can convert that to integer by doing:
Select * from mytable where CAST(version as integer)>=11;
Hope this helps you.
CAST(expr AS type)
For example: you have a column named "version", and you stored value "11" in it. Now you can convert that to integer by doing:
Select * from mytable where CAST(version as integer)>=11;
Hope this helps you.
July 12, 2011
Windows 2003, XP, recursive taking file and folders ownership and permissions
I found that the security tab on the file properties did not work for me when taking ownership and setting permission for a full directories with multiple sub directories. The follow method did the trick:
1. Download fileacl
2. Run: cd C:\Program Files\fileacl
3. fileacl "My directory" /s myusername:RWD /FILES /SUB
1. Download fileacl
2. Run: cd C:\Program Files\fileacl
3. fileacl "My directory" /s myusername:RWD /FILES /SUB
July 1, 2011
Subscribe to:
Posts (Atom)