Archive for the 'programming' Category

Where’s My Car? for Palm Pre/Pixi

Thursday, March 4th, 2010

I’ve submitted my first WebOS application to their App Store!

Where’s My Car? helps you find your car in a crowded parking lot. When you leave your car, simply open the application. (It will automatically get your current GPS location) Leave the application open, and when you’re done doing whatever it is you have to do, click “Take Me To It!” An arrow will show up (as well as a distance measurement). Simply walk in the direction of the arrow, and you’ll be quickly guided back to your car! BTW, I originally wrote this app as a present for my wife. :) I’ve decided to place it on the App Store as a FREE app because I don’t see why the other apps that do the same thing charge $5 for such a simple feature. Let me know if you like it! :)

UPDATE: It has been approved/published!  To download, open the App Catalog.  Search for “car”.  Click the coins icon in the lower-right to show only FREE apps, and “Where’s My Car?” should be the first in the list!  :)

UPDATE 2: Click here to download:  Where’s My Car?

Screenshots after the break…

(more…)

Dependency Injection: Coke with Lime

Friday, January 29th, 2010

I have in the past expressed skepticism regarding the utility of Spring’s XML-based dependency injection configuration files. A bit ago, in one of these conversations, I was pointed to Martin Fowler’s article on dependency injection. I found it hilarious.

(more…)

Brain-Dead

Monday, December 21st, 2009

Java is somewhat brain-dead at times. For instance:

while(c=System.in.read()>-1){
  System.out.print(backspaceChar);
}

Doesn’t do what you’d expect. (hide console input) It appears that System.in is being silently buffered.

So a little googling: http://java.sun.com/developer/technicalArticles/Security/pwordmask/

Sun’s recommendation is a busy-wait loop in a separate thread that constantly rewrites the previous character?!? I mean, seriously, WTF?!?

Edit: It looks like Sun implemented a new API for non-echoing prompts in v1.6: http://java.sun.com/javase/6/docs/api/java/io/Console.html

But this is still crappy. Introducing a new API to partially work around the broken functionality of an old API is how you get bloated monstrosities to begin with.

XiMpLode

Wednesday, July 29th, 2009

It has been said before, but it deserves repeating: XML is overused. And often, made unnecessarily over-complicated for the task. Take for instance the example “A Simple Soap Client“.

Here is the request:

<?xml version="1.0"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <SOAP-ENV:Body>
    <calculateFibonacci
      xmlns="http://namespaces.cafeconleche.org/xmljava/ch3/"
      type="xsi:positiveInteger">10</calculateFibonacci>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here is the response:

<?xml version="1.0"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" />
  <SOAP-ENV:Body>
    <Fibonacci_Numbers
      xmlns="http://namespaces.cafeconleche.org/xmljava/ch3/">
      <fibonacci index="1">1</fibonacci>
      <fibonacci index="2">1</fibonacci>
      <fibonacci index="3">2</fibonacci>
      <fibonacci index="4">3</fibonacci>
      <fibonacci index="5">5</fibonacci>
      <fibonacci index="6">8</fibonacci>
      <fibonacci index="7">13</fibonacci>
      <fibonacci index="8">21</fibonacci>
      <fibonacci index="9">34</fibonacci>
      <fibonacci index="10">55</fibonacci>
    </Fibonacci_Numbers>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Dear $DEITY, why do we need to define a new data type to hold a list of integers? And what in the world is that “index” attribute doing there? IT’S A FUCKING LIST. This is like a real-life example of the old XML binary encoding joke:

<data>
  <binary>
    <bit index="0">0</bit>
    <bit index="1">0</bit>
    <bit index="2">1</bit>
    ...
    <bit index="n">1</bit>
  </binary>
</data>

It’s just sad…

For the sake of it, let’s compare to a JSON-RPC version: (not the epitome of efficiency mind you, but an order of magnitude better)

--> { "method": "calculateFibonacci", "params": [10,], "id": 1}
<-- { "result": [1,1,2,3,5,8,13,21,34,55], "error": null, "id": 1}

Which would you rather use? :)

Easy Python/Numpy CUDA/CUBLAS Integration

Monday, April 13th, 2009

CUDA is Nvidia’s C-like API for non-graphic number crunching on their 8xxx level and above video cards. For certain operations, it is amazingly fast. Unfortunately, it is painful in the extreme to use, especially when compared to Numpy, Python’s wonderful scientific computing package.

So, to marry the two, I wrote for myself some wrapper code. It’s pretty much only good for one thing: multiplying large matrices together really fast. But it’s really good at it. (and it’s really easy to use) For example:

import numpy
from pycublas import CUBLASMatrix
A = CUBLASMatrix( numpy.mat([[1,2,3],[4,5,6]],numpy.float32) )
B = CUBLASMatrix( numpy.mat([[2,3],[4,5],[6,7]],numpy.float32) )
C = A*B
print C.np_mat()

All CUBLAS alloc and free calls are mapped to the CUBLASMatrix object’s life in Python, so you don’t have to worry about memory management. (other than filling up the card, or course)

Here are some performance numbers: (includes memory transfer times)
(4160×4160)*(4160×4160) = 43.0X faster than numpy
(4096×4096)*(4096×4096) = 34.0X
(3900×3900)*(3900×3900) = 47.3X
(2048×2048)*(2048×2048) = 28.2X
(1024×1024)*(1024×1024) = 58.8X
(512×512)*(512×512) = 24.1X
(256×256)*(256×256) = 6.3X
(128×128)*(128×128) = 1.1X
CPU: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz stepping 06
GPU: nVidia Corporation GeForce 8800 GT (rev a2)

Note: This version only supports float32.
Note: CUBLAS limits matrix dims to (65536×65536).

Source code available here: pycublas.py (rename download to pycublas.py to use)

Google's N-gram Corpus LDC2006T13

Tuesday, December 9th, 2008

Google’s LDC2006T13 corpus is organized in an understandable but slightly annoying way; as a tar of split gzipped files. To avoid having to untar it repeatedly, (in fact, at all, as it’s >100GB extracted), I wrote a small Python generator that let’s you iterate over them in their compressed state. Usage is something like this:

corpus = LDC2006T13()
for ngram, count in corpus.ngrams(3):
  print ngram, count

Code is here: LDC2006T13.py

Installing PyCUDA on Ubuntu 8.10

Tuesday, November 18th, 2008

I had to spend a bit of time working out the install procedure for PyCUDA on Ubuntu 8.10. So I thought I’d share…

cd downloads/

Install the CUDA toolkit. Ubuntu already comes with the 177.80 NVidia driver, so I didn’t install v177.73.

# install CUDA
wget http://developer.download.nvidia.com/compute/cuda/2_0/linux/driver/NVIDIA-Linux-x86_64-177.73-pkg2.run
wget http://developer.download.nvidia.com/compute/cuda/2_0/linux/toolkit/NVIDIA_CUDA_Toolkit_2.0_ubuntu7.10_x86_64.run
wget http://developer.download.nvidia.com/compute/cuda/2_0/linux/sdk/NVIDIA_CUDA_SDK_2.02.0807.1535_linux.run
chmod +x *.run
sudo ./NVIDIA_CUDA_Toolkit_2.0_ubuntu7.10_x86_64.run
# accepted default install location: /usr/local/cuda
su -
echo "include /usr/local/cuda/lib" >> /etc/ld.so.conf.d/cuda.conf
ldconfig
cd /usr/bin/
ln -s /usr/local/cuda/open64/bin/* .
exit

Install Boost libs, v1.35.

sudo apt-get install libboost-python1.35-dev

Install PyCUDA.

wget http://pypi.python.org/packages/source/p/pycuda/pycuda-0.91.tar.gz#md5=339dac0641cc5da2f5c153d134592ed3
tar -zxvf pycuda-0.91.tar.gz
cd pycuda-0.91/
./configure

Edit siteconf.py to look like this…

BOOST_INC_DIR = ['/usr/include/boost/']
BOOST_LIB_DIR = ['/usr/lib']
BOOST_PYTHON_LIBNAME = ['boost_python-mt-py25']
CUDA_ROOT = '/usr/local/cuda/'
CUDADRV_LIB_DIR = []
CUDADRV_LIBNAME = ['cuda']
CXXFLAGS = []
LDFLAGS = []

Then take her home…

python setup.py build
sudo make install

Now to test:

#export C_INCLUDE_PATH=/usr/local/cuda/include/
#export CPLUS_INCLUDE_PATH=/usr/local/cuda/include/
export PATH=$PATH:/usr/local/cuda/bin/
cd test
python test_driver.py

The tests run successfully for me, sans test_mempool (__main__.TestCuda). I’ll update this as I find out more.

ARPA Language Model File Format

Tuesday, August 12th, 2008

The format of a ARPA language model file, as far as I can tell, is not documented outside of the CMU SLM toolkit source code. I’m regurgitating it here in the hopes that future Google searches on this topic are more fruitful than mine were. :)

/* This is the format introduced and first used by Doug Paul.
   Optionally use a given symbol for the UNK word (id==0).
*/
/*
Format of the .arpabo file:
------------------------------
\data\ ngram 1=4989 ngram 2=835668 ngram 3=12345678 \1-grams: ... -0.9792 ABC -2.2031 ... log10_uniprob(ZWEIG) ZWEIG log10_alpha(ZWEIG) \2-grams: ... -0.8328 ABC DEFG -3.1234 ... log10_bo_biprob(WAS | ZWEIG) ZWEIG WAS log10_bialpha(ZWEIG,WAS) \3-grams: ... -0.234 ABCD EFGHI JKL ... \end\ */

SVN/Trac Integration

Friday, June 27th, 2008

A long time ago I wrote an article titled CVS/Bugzilla Integration. Here is an updated version for subversion and trac.

Note that it doesn’t require access the trac python libs or database; it just uses HTTP. But it does require BeautifulSoup. Install it by adding it to your hooks post-commit script. (it takes the normal params of REPOS and REV).

(more…)

gPapers in Nature

Saturday, May 3rd, 2008

Check it out… I was mentioned in a recent Nature article about research paper management tools:

http://www.nature.com/news/2008/080430/full/453012b.html (doi:10.1038/453012b)

Cool, eh? :-)


<Kered.org>   © Copyright 2000-2005 by Derek Anderson
Get Firefox