tech
GTK Recently Used updated with inotify!
Heres a cute hack, an easy way to make any file you open/change from the command line appear in your GTK file widget's "Recently Used" list, it uses python's pyinotify package available in apt, and pythons python-gtk2 package.
Something that's very handy, for example when you are editing something on the command line and attaching to an email and need to browse to the location, or when you've wget'ed a file and need to open it from a gnome application, the list goes on!
Prototype JS selectors versus jQuery
In Prototype JS you get given an element, but in jQuery you get given a list of elements, which makes things confusing when selecting a class of elements in Prototype JS or jQuery
jQuery, Oh so simple.
$("p").click(function () {
$(this).something();
});
Prototype JS...
Fivestar voting.. Do you even need it? Or is it just a cool idea
I came across this article about youtube ditching its fivestar rating basically because users treat it as a binary thing, either they love it (5 stars) or hate it (0 stars) or simply dont bother voting, there are some edge cases where users DO bother voting however.
more here... http://youtube-global.blogspot.com/2009/09/five-stars-dominate-ratings.h...
python unicode escaping to xmlescape
If you get errors like..
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 48: ordinal not in range(128)
try and escape them to something supported locally..
(from http://www.amk.ca/python/howto/unicode)
particularly
u.encode('ascii', 'xmlcharrefreplace')
>>> u = unichr(40960) + u'abcd' + unichr(1972)
>>> u.encode('utf-8')
'\xea\x80\x80abcd\xde\xb4'
>>> u.encode('ascii')
Traceback (most recent call last):
File "", line 1, in ?
python regex substitution with backreferences, don't forget to escape!
amount = re.sub(r'\.(\d)0$', '.\1', amount)
wont work but...
amount = re.sub(r'\.(\d)0$', '.\\1', amount)
will!
Jumping on a session with curl, tcpdump and grep
Sometimes you want to use the 'curl' command line utility to grab a page using your current session that you were browsing in from your web browser.
So you need to to first capture the cookie header, assuming the host you're talking to is not smart enough to use a rolling session ID or something, it should be pretty straight forwards.
The following tcpdump and grep line tells tcpdump to output STDOUT with line buffering enabled, and the grep pipe tells it to treat all input as text (as it's binary from tcpdump), and to stop after the first match.
Python libxml2 not quite threadsafe, use lxml instead for xpathing!
Python libxml2 not quite threadsafe, use lxml instead for xpathing! although lxml is just a wrapper for the same libxml2 library that python's libxml2 module (python-libxml2) uses, it will act very strange when you're calling parseDoc in a loop in your threads.
text() is a special xpath function in lxml
import lxml.etree as etree
f = StringIO.StringIO('<hours>anytime</hours>')
tree = etree.parse(f)
res = tree.xpath('//hours/text()')
print res[0]
Stephen Conroy
Just linking to the real stephen conroy website. :D
LXML removing an element that you find
I've been using LXML (http://codespeak.net/lxml/) for a new project, Kinda tricky, not quite obvious if you want to drop an element and its children that you find, but the rest of the lxml library is pretty obvious after a little while
so you may have something like
<food>
<taste>sour</taste>
</food>
so you would..
type="sour"
elem = xml.xpath('//food[taste="%s"]' %(child))
elem[0].getparent().remove(elem[0])
ODBC with Python (pyodbc) to MS SQL (SQL Server - Microsoft)
Was having trouble figuring out pyodbc http://code.google.com/p/pyodbc/ with my ODBC configuration to talk to a MS SQL or "Sequel" as some people would have it
You'll need a couple of packages installed
tdsodbc - ODBC driver for connecting to MS SQL and Sybase SQL servers
odbcinst1debian1 - Support library for accessing odbc ini files
odbcinst - Helper program for accessing odbc ini files
so just
apt-get install tdsodbc odbcinst1debian1 odbcinst
