Browsed by
Category: Programming

Your First Chome Extension

Your First Chome Extension

I made my first browser extension recently. Turns out that it is refreshingly easy.

I use Google Chrome. One of my favorite websites is SlickDeals.net, which I must admit to occasionally browsing at work. The problem is that SlickDeals makes its money via referrals. i.e. if I post a link to newegg.com, SlickDeals parses the URL and generates a redirect via a referral URL.

So:

http://www.newegg.com/Product/Product.aspx?Item=N82E16889005129

becomes:

http://slickdeals.net/?sdtid=2702819&sdfpid=47595&sdop=1&sdfid=9&u2=http://www.newegg.com/Product/....

This would be fine, however my work blocks all the intermediate sites the modified link redirects via, so it is necessary to copy the http://www.newegg.com/…. URL, which fortunately is in plaintext, from the modified URL and paste it into a new window.

After doing this 100 times or so I was pretty fed up so I wrote an extension to parse the modified URLs and return them to their original form.

Creating a Chrome extension to parse and modify page content

Android & SQLite – 1MB limit, IOException and general woes.

Android & SQLite – 1MB limit, IOException and general woes.

This long weekend I worked on an app: Scrabble For Anagrams. The UI took about 8 hours. The engine to generate and perform rapid lookups of character permutations took about 8 hours. After 2 days of hard work I believed the app was working great and was nearly ready to go on the market. The dictionary was converted into a SQLite DB outside of the android application and was included as an asset.

However, my original dictionary (found online) contained only 10K words and I pretty rapidly found some word combinations that were valid but weren’t in the dictionary – clearly unacceptable. No problem! I found a freely available 400K word dictionary, generated the new DB and placed it in the asset folder. Build, run and bam! IOException.

Dump, Split and Rebuild the DB

CamDDR

CamDDR

8 years ago a buddy introduced me to DDR. I went from ashamed, to bemused to loving it within about a year and I got pretty good. I full-combod Era at expert a couple of time.

With all the Kinect hype, I’ve been thinking it would be an excellent device for a virtual DDR pad. Unfortunately I don’t have a Kinect – but I do have a crappy cheap webcam and so CamDDR was born.

You can find instructions and download the beta here: CamDDR

I’m not out of ideas yet and I think I know how to make version 0.3 deal with back steps a whole lot better, so it will be interesting to see where this goes. If I can pass Era on the second level of difficulty I’ll be happy.

Py2EXE, PIL and ImageFont Error

Py2EXE, PIL and ImageFont Error

After using Py2EXE to generate a distributable binary from a project that used the Python Imaging Library (PIL) I got an error like this:

File “PIL\ImageFont.pyc”, line —, in load_path IOError: cannot find font file

A quick google yields this page: http://www.py2exe.org/index.cgi/PILAndFontfiles

Unfortunately dropping the files into the Dist directory wasn’t enough – when cycling through path directories to find the file it searches for …/dist/library.zip rather than simply /dist.

The fix is simple, edit your ImageFont.py file and in the load_path(filename) function, change:

def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
if Image.isDirectory(dir):

to:

def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
dir = os.path.dirname(dir)
if Image.isDirectory(dir):

This worked for me.