Sunday, February 28, 2010

AVR: storing a 2d array in PROGMEM

I've just been fangling with a UV Painter project (row of LEDs to 'paint' on a glow-in-the-dark-wall). I quickly ran out of RAM when adding patterns to the system and learned how to add variables to the Flash program memory instead. Pretty simple and very useful:

#include <avr/pgmspace.h>

const uint8_t mCylonScan[10][N_LED] PROGMEM = {

Then to access the data you just do the following (where 'i' and 'j' are loop variables):

data = pgm_read_byte(&(mCylonScan[i][j]));

See the AVR libc docs for more details.

Friday, February 26, 2010

Manipulating Bash Strings

I'm finding myself looking these up quite a lot, so here's a little cheat sheet of the basics.

Using the string "ABCDEFG12345" as an example:

> string="ABCDEFG12345"
> echo $string

> #Replacement:
> echo ${string/ABC/___}

> #Replacement with character class
> echo ${string/[ABC4]/_}

> #Replace all occurrences:
> echo ${string//[ABC4]/_}

> #Extract from a defined position in the string
> echo ${string:7}
> echo ${string:7:3}

> #substring removal (from the front of the string)
> echo ${string#ABC}
> echo ${string##ABC} #strips the longest substring match
> string2="abcABCabc123ABCabc
> echo ${string2#a*C}
> echo ${string2##a*C}
> # use the % sign to match from the end
> # % for shortest and %% for longest substring match
> echo ${string%45}

Thursday, February 11, 2010

Use csplit to split SDF files (or contextually split any file)

Say you want to split an SDF into individual entities, you could write a Perl script/one-liner (which is what I've been doing for a long time) or you could just use csplit. Thanks to Pat and Jessen for pointing this one out.

e.g. say you had an SDF, test_mols.sdf, with 8 molecules in it and you wanted individual mol files:

> csplit -kzsf "test_mols" -b %0d.mol test_mols.sdf /\$\$\$\$/+1 {*}

This would result in 8 files called test_mols00.mol through test_mols07.mol. Unfortunately these would still contain the SDF delimiter at the end of the file (so, technically these are still SDFs). That's pretty easy to clean up with something like:

> perl -ni -e 'print unless /\$\$\$\$/' *.mol

See the csplit manpage for more details.

Tuesday, February 2, 2010

autolinkification in bugzilla

I often refer to other bugs in a Bugzilla comment. These are 'autolinkified' by bugzilla. I've only just learned that you can refer to a comment in a bug as well and have this 'autolinkified'.

See the Bugzilla hintandtips page.

Short answer:

Bug autolink:" bug 1234"
Comment autolink:"bug 1234, comment 12"
attachment: autolink" bug 1234, attachment 4"