April 30, 2015

vim ctags tags path

This line in your ~/.vimrc should help:
set tags=./tags,tags;$HOME

It tells Vim to look for a tags file in the directory of the current file, in the current directory and up and up until your $HOME (that's the meaning of the semicolon), stopping on the first hit.

April 27, 2015

golang win32 UI

https://github.com/lxn/walk

OR

https://github.com/AllenDang/gform

OR

https://github.com/andlabs/ui

April 23, 2015

USB terms

In the USB world, the most basic data transfer is done in packet, but to understand the on-the-wire protocol, there are other things to understand.

Packet
USB Packet types: (Source: http://www.usbmadesimple.co.uk/ums_3.htm)

PID Type PID Name PID<3:0>*
Token OUT 0001b
IN 1001b
SOF 0101b
SETUP 1101b
Data DATA0 0011b
DATA1 1011b
DATA2 0111b
MDATA 1111b
Handshake ACK 0010b
NAK 1010b
STALL 1110b
NYET 0110b
Special PRE 1100b
ERR 1100b
SPLIT 1000b
PING 0100b
Reserved 0000b

Transaction: 
   
One transaction has 3 packets: Token + Data + Handshake for a successful transaction. (*). Nak and Stall error condition could happen after Token when no data is available.

There are 3 types of transactions: IN, OUT, SETUP

 *: For IN and OUT transactions used for isochronous transfers, there are only 2 packets; there is no handshake packet.

Transfer:
There are 4 types of transfer:

  • Control 
  • Interrupt
  • Bulk
  • Isochronous (such as audio data)
HID device only uses Control and Interrupt

Control transfer = 3 transactions: SETUP + IN/OUT DATA + STATUS(IN/OUT transaction)
Other transfers has just one transaction: IN/OUT data.

In general, you want to pay attention to Transfer or Transaction level, not packet level. 

April 22, 2015

prevent ssh client timeout

Add this in /etc/ssh/ssh_config for Linux and ~/.ssh/config for Mac:


Host *
ServerAliveInterval 120

linux cp without overwrite

You can use "-n" option.

If you are on a embedded linux box with busybox, it does not have that option. You can this instead:

false | cp -i source destination 2>/dev/null

April 16, 2015

Vim show C function name

Put this in your .vimrc file, and use key "f" to show current function name:

fun! ShowFuncName()
  let lnum = line(".")
  let col = col(".")
  echohl ModeMsg
  echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW'))
  echohl None
  call search("\\%" . lnum . "l" . "\\%" . col . "c")
endfun
map f :call ShowFuncName() <CR>

April 15, 2015

golang combine static data (css/js/images/) with binary file

https://github.com/tiebingzhang/statik (zip the contents and compiled it into go source code, very small code base, this is a github fork with the slash fix)

https://github.com/jteeuwen/go-bindata

https://github.com/GeertJohan/go.rice (can either compile zip into go source, or append the zip to existing go EXE, more flexible but code base is a little larger)

April 14, 2015

script to detected unused C files

If you have a large project with a lot of C files, once you compiled them, you will end up with a lot of .o files. Then you can use the .o files to find out which .c files is not used (conditionally compiled/not compiled). To do this, follow the steps below:

1. cd subdir
2. ls -1 > ../1.out
3. gawk -f lsnu.awk ../1.out

The lsnu.awk script
{
        if ($1 ~ /\.c$/){
                cfiles[$1]=1;
                print $1;
                next;
        }
        if ($1 ~ /\.o$/){
                ofiles[$1]=1;
                #printf("%s\n",$1);
                next;
        }

}

END{
        printf("-------------\n");
        for ( i in  cfiles){
                f=i;
                gsub(/\.c$/,".o",i);
                if (ofiles[i]!=1){
                        printf("%s ",f);
                        }
        }
        printf("\n");
}