Thursday, June 30, 2011

Force FireFox to reload a short cut icon

Type in the url of the icon file and load the image.

utf-8 encoded files in python

From this PeP:

Adding a line that looks like:

# This Python file uses the following encoding: utf-8

Is sufficient to avoid the

no encoding declared; see http://www.python.org/peps/pep-0263.html for details

error

Monday, June 27, 2011

minidom.writexml handling unicode errors

Problem:
Writing xml with unicode characters does not work, even with the encoding set to 'utf-8'. Always results in something like

UnicodeEncodeError('ascii', u'kr\xf6se1989', 2, 3, 'ordinal not in range(128)')


Solution (from here):
Use the codecs module and manually open the file in utf-8 mode for writing

import codecs
doc.writexml(codecs.open(fname,'wb','utf-8'), encoding='utf-8')

SQL query binding for a list using Python

From here:

l=[1,2,3,4] placeholder= '?' # Works For SQLite. placeholders= ', '.join(placeholder for dummy in l) #puts in len(l) '?' marks, separated by ', ' query= 'SELECT name FROM students WHERE id IN (%s)' % placeholders cursor.execute(query, l)

Thursday, June 16, 2011

Firefox + Mac OS X + bangla fonts = disaster

Please see this bugzilla issue.
In short:

  1. Test any bangla font you install using Mac OS X's fontbook. Do not install any font that shows warnings or errors
  2. The only Bangla font that I found to work with Firefox and not crash it on Mac OS X is at onkur.

Sources for Bangla unicode fonts

Tuesday, June 14, 2011

Strange inefficieny of pysqlite over sqlite (and apsw)

I've been happily using pysqlite to access my sqlite databases from python. Suddenly, I find, however, that there is a query that runs much, much slower in pysqlite than in apsw and the sqlite shell. I've filed a bug report but it looks like I'll be switching to apsw until this thing gets resolved.

Saturday, June 11, 2011

Another open source reference manager : Paperpile

From a blog post here, I found out about Paperpile. I downloaded and ran it, but haven't used it, since I use my own, but Paperpile has  a nice clean look. Though there is GPL code of Paperpile on github, the main website seems to indicate the author has hopes of commercializing (and closing the source) to Paperpile if things look successful.

Wednesday, June 8, 2011

Compress camera video for a windows machine

mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=1:vbitrate=375000:mbd=2:keyint=132:vqblur=1.0:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 -oac copy -o /dev/null MVI_0052.AVI
mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=2:vbitrate=375000:mbd=2:keyint=132:vqblur=1.0:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 -oac copy -o output.avi MVI_0052.AVI

Tuesday, June 7, 2011

Python and word documents

From here, using only standard python modules:

import zipfile, re

docx = zipfile.ZipFile('/path/to/file/mydocument.docx')
content = docx.read('word/document.xml')
cleaned = re.sub('<(.|\n)*?>','',content)
print cleaned


But, if you want to mess around in more detail in the document, then we can use the python-docx module.

Monday, June 6, 2011

discount bug

import discount
a = discount.Markdown('')
a.get_html_content()
--> Yields TypeError
TypeError: 'NoneType' object is unsubscriptable
Should return a blank.

Found that markdown or markdown2 give comparable performance, so now no longer using discount.

Friday, June 3, 2011

Using adminer on Mac OS X

adminer is a nice php based sqlite manager. I prefer the firefox plugin "sqlite manager" but it currently has a strange issue with FF5 that basically makes it unworkable, so I was looking for an alternative to tide me over.

I really don't want apache running all the time on my computer and don't want people browsing to my computer, so what I needed to do was:

  1. Download the adminer php script into /Library/WebServer/Documents/
  2. Change /etc/apache2/httpd.conf to allow running of php scripts (uncomment the line that begins: LoadModule php5_module
  3. Start the apache server: sudo apachectl -k start
  4. Operate the script by going to localhost
  5. Stop the server: sudo apachectl -k stop  

Bottlepy server exits during sleep (Mac OS X)

Problem: Bottlepy server exits when computer comes out of sleep
Solution: Set "reloader" option to False.