Friday, February 26, 2010

math-like programming

i couldn't prove it at the time, but i had a feeling that i knew what i was doing....
i think i better understand now why it helps to keep a piece of code running correctly with unit tests while modifying it. it's like a mathematical equation. you can use substitutions and properties of operators and functions to modify the expressions, but only if you maintain equality at every step. maintaining that equality requires an understanding of the underlying math objects, and knowing which way to transform the expressions requires skill and creativity. but the hardest part is to lay down the governing equations to begin with -- to state the paradoxically precise abstraction of reality.
inasmuch as a computer language is an alternate grammar for discrete math, it is to be expected that to manipulate an existing expression while maintaining correctness is easier than to derive an algorithm from scratch (or from incorrect code). sometimes i have correct code that i still want to modify, for example, to generalize or to optimize. i need to think like a compiler and make my modifications in smaller steps, each maintaining correctness with respect to the unit tests, rather than try to leap at once to a large rewrite. faster, easier, and clearer thinking, often with solutions that present themselves along the way.
for example, can i move that assignment from the beginning to the end of the loop? i want to eliminate that variable; first i'll make it redundant. i think these two expressions are equivalent, so i'll put in an assert to test that before replacing the old one. now i have a better way to refactor and i know why to do it.

Thursday, February 25, 2010

numpy.searchsorted

i don't know why i keep forgetting how to find the first or last index of a value inside a numpy array. quick googling will turn up things like (findIn == toFind).all(1).nonzero()[0][0], which works but gets _really_ slow for large arrays since it's searching the whole thing. searchsorted is all i need, 99% of the time, and i don't know why it's not cited more often. i finally remembered (again) this latest time when i found myself reinventing a binary search (which is what searchsorted does).

Wednesday, February 24, 2010

myhdl

cool project converts python directly to vhdl or verilog. looks like it's under active development, with demo projects posted. if i ever need to use an fpga or cpld again, i know where to go.
and one of the examples uses the cypress fx2 usb controller chip, with references to other dsp interface projects (at 30 MB/s) including a 33khz adc fpga/fx2 microcontroller demo.

Monday, February 22, 2010

urlbst

might need to check out the urlbst package some time. it can make hyperlinks in my bibliographies to the referenced articles.

Friday, February 19, 2010

data acquisition, serial interfaces

nice little article summarizing the various serial bus standards for ic networks: rs-232, rs-422, rs-485, spi, i2c, mirowire, 1-wire, and plain old bit banging. a bit dated at 2002, but still handy.
looks like rs485 is what you need for high-speed transmission over significant distances. spi slows down a lot when you take it off the pcb and looks more like a can bus.
maybe the way to go for low volume is a tiny linux server. lantronix makes the xport pro. digi international makes the digiconnect me (or digi connectme?) that can run picotux. marvell semiconductor makes the sheevaplug. all pretty small and lightweight, and you can just plug an ethernet cable into the darn thing and forget about it.
hmm, the xport pro seems to be highly geared toward network services and the external interface is limited to ~8kB/s serial. digi connect me 9210 might be better for data logging. or maybe gumstix? it's hard to find specs for data acquisition on their website.
mccdaq.com have some ~reasonably priced boards, though their stuff looks like it's either pci boards or clunky usb endpoints. multichannel, though.
another route would be a high-speed usb (up to 40MB/s) with the cypress ez-usb fx2lp (like cyzc68013a). check out www.elrasoft.com/hsusbm.htm and the project listed there by dcarr.

Wednesday, February 17, 2010

mark levin show

i definitely prefer downloading the mp3 files rather than listen through the website's streamer. so here's how to for mark levin:
in http://www.marklevinshow.com/rss/ilevin.xml look in the enclosure tags. they have url metas that have the full url to the mp3s. wget away!

Tuesday, February 16, 2010

checkinstall with non-root

i wanted to use checkinstall as a non-root user, with sudo, and i found a way to make it work. i made a directory called checkinstall/packagename and cd'ed to it (this helps checkinstall get the right package name). then i ran 'checkinstall easy_install packagename' and it it worked great, once i had the following change: after this part of the checkinstall script
echogn "Installing Debian package..."
dpkg -i $DPKG_FLAGS "$DEBPKG" &> ${TMP_DIR}/dpkginstall.log
okfail
i put in this:
# added this to try sudo
if [ $? -gt 0 ]; then
echo "sudo dpkg -i $DPKG_FLAGS \"$DEBPKG\" &> ${TMP_DIR}/dpkginstall.log"
echogn "Installing Debian package with sudo..."
echo
sudo dpkg -i $DPKG_FLAGS "$DEBPKG" &> ${TMP_DIR}/dpkginstall.log
okfail
fi
since i'm installing stuff in my home dir, i have to answer yes when checkinstall asks if i want to see these files (so they can get included in the package and not excluded as config files as checkinstall expects).
now it all works (tested with easy_install) and it shows up in synaptic and everything.
also, i found what i am pretty sure is a bug. pretty obvious, so i'm surprised no one else seems to have posted anywhere about it. i changed the line
grep '^/home' ${TMP_DIR}/newfile > /${TMP_DIR}/unwanted
to
grep '^/home' ${TMP_DIR}/newfiles > /${TMP_DIR}/unwanted