Tuesday, October 26, 2010

Ctrl-Enter in Thunderbird

Did you know that Ctrl-Enter in Thunderbird sends your email message immediately? If you do, you probably learned it the hard way, by sending a half-written email, like I just did. Awkward . . .

To get rid of this behavior, install the keyconfig extension. Once you have installed the extension and restarted Thunderbird, go to the Tools menu > Keyconfig. Choose "Send Now", and click the disable button.

If you installed keyconfig, but you can't find the "Send Now" option:

1) Open Thunderbird
2) Start composing a new message (in a new window)
3) In the main Thunderbird window, go to the Tools menu > Keyconfig
4) At the top of the Keyconfig window, there is a dropdown box, with one entry for each open Thunderbird window
for example:
- Inbox
- Write (no subject)
- Keyconfig
5) Choose the "Write . . ." window in the Keyconfig dropdown box
6) Send Now should now be listed in the Keyconfig listbox
7) Select Send Now, and click Disable
8) done!

Tuesday, July 20, 2010

Nested list comprehensions in Python

Python's nested list comprehensions often hover on the edge between elegance and obfuscation.

I made some examples to show the order of evaluation, and the results of adding/removing the nested bracket symbols.


matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]

# This flattens and transposes the matrix.
c = [row[i] for i in range(len(matrix)) for row in matrix]
d = []
for i in range(len(matrix)):
for row in matrix:
d.append(row[i])
assert(c == d)
print c # [1, 4, 7, 2, 5, 8, 3, 6, 9]

# This flattens the matrix.
e = [row[i] for row in matrix for i in range(len(matrix))]
f = []
for row in matrix:
for i in range(len(matrix)):
f.append(row[i])
assert(e == f)
print e # [1, 2, 3, 4, 5, 6, 7, 8, 9]

# This transposes the matrix.
a = [[row[i] for row in matrix] for i in range(len(matrix))]
b1 = []
for i in range(len(matrix)):
b2 = []
for row in matrix:
b2.append(row[i])
b1.append(b2)
assert(a == b1)
print a # [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

# This returns the matrix unchanged.
g = [[row[i] for i in range(len(matrix))] for row in matrix]
h1 = []
for row in matrix:
h2 = []
for i in range(len(matrix)):
h2.append(row[i])
h1.append(h2)
assert(g == h1)
assert(g == matrix)
print g # [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

# This oddity builds up a nested list from simple lists.
k = [zip(j,j) for j in [range(i) for i in range(4)]]
m1 = []
for i in range(4):
m1.append(range(i))
m2 = []
for j in m1:
m2.append(zip(j,j))
assert(k == m2)
print k # [[], [(0, 0)], [(0, 0), (1, 1)], [(0, 0), (1, 1), (2, 2)]]


Thanks to Luka Marinko for his instructions for setting up syntax highlighting on Blogger.

Monday, March 30, 2009

Django on Twisted

Update from the Twisted sprint - David Reid is working on getting Django running on top of twisted. It's up and serving a simple app. Instructions here

Here's the money line:
twistd -no web --wsgi=myapp.application

Monday, February 4, 2008

Blogger wins!

After years of holding a geek hard line on running my own server for my personal website, I have decided to move to blogger. Another brick in the Google borg, I know; but I must admit that my poor server, starved of attention, too often fell prey to downtime, log overflows, and botched upgrades. For me, sysadmin is a chore, and if someone is willing to do it for me for free, then I (finally) say amen.

I'll port posts here as time permits (i.e. never).