Counting lines of code 

To measure the lines of code in a codebase (on a standard Linux machine):

find -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.hpp" | while read i; do wc -l "$i"; done | cut -d " " -f 1 | awk '{total = total + $1}END{print total}'

The while read is needed to join together file names with spaces (versus using -exec wc -l {} \;).
[ add comment ] ( 83 views ) permalink

MySQL REGEXP accepts the standard entries like [:digit:] (equivalent to [0-9] but better practice due to languages etc). However in MySQL (or perhaps SQL in general) [ and ] are special characters, and need to be escaped by doubling them. [:digit:] needs to be [[:digit:]] in the SQL query.
[ add comment ] ( 86 views ) permalink
Python MySQLdb and string substitution 

The Python DB API specifies multiple formats for substituting strings into query strings.

pyformat implies it uses the Python % string substitution rules. However, one difference is any string substitutions will be quoted (have '' put around the value). This is a problem if you embed the value inside an existing string.

cursor.execute( "SELECT * WHERE `name`='prefix.%(val)s.postfix'", {'val':'foobar'} ) is parsed into "SELECT * WHERE `name`='prefix.'foobar'.postfix'" which is not valid SQL.

To work around this, I used cursor.execute( "SELECT * WHERE `name`=CONCAT('prefix.', %(val)s, '.postfix')", {'val':'foobar'} )
[ add comment ] ( 89 views ) permalink
LIRC on Ubuntu 12.04 

The lircd init script (/etc/init.d/lirc) sets the ir driver to exclusively use the "lirc" protocol (which forwards all IR to LIRCD?). However, if you want to use the devinput system, I had to enable "nec" protocol, and use /dev/input/by-path/ as appropriate (versus /dev/lirc0). The protocol required may vary depending on the remote you are using (or emulating in the case of a programmable remote). Search for "/sys/class/rc/" and protocols in the lirc init script.
[ add comment ] ( 92 views ) permalink
Logitech Headset 

I tried plugging in a Logitech USB headset, and Windows7 x64 didn't recognize the device (unable to install driver). The solution was to copy usb.inf from C:\Windows\System32\DriverStore\FileRepository\usb.inf_amd64_neutral_e2b28ecac19a29af to C:\Windows\Inf (there was no existing usb.inf) and then re-insert the device.

Currently the microphone is silent, which may be a hardware issue.
[ add comment ] ( 83 views ) permalink

<<First <Back | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Next> Last>>