Feeds:
Posts
Comments

Archive for the ‘Technique’ Category

You start your day, happily working with dictionaries…Life is good.

>>> mydict = {‘key-a’: ‘value-a’, ‘key-b’: ‘value-b’}
>>> mydict['key-a']
‘value-a’

All of a sudden, storm clouds appear. Your dictionary variable accidentally gets assigned a list, and life is no longer good!

>>> mydict = {‘key-a’: ‘value-a’, ‘key-b’: ‘value-b’}
>>> mydict['key-a']
‘value-a’
>>> mydict = []
>>> mydict['key-a']
Traceback (most recent call last):
File [...]

Read Full Post »

Was playing around with nginx on Centos 5 (EPEL package).
Most of the time I ran:
service nginx restart
I would get this message in the /var/log/nginx/error.log file:
panic: MUTEX_LOCK (22) [op.c:352].
After some hunting around, it appears to be a known bug in nginx (perhaps perl in nginx?)… Anyway, a simple workaround is to do this:

service nginx stop
service nginx [...]

Read Full Post »

I highly recommend reading this excellent writeup on Python super(), python __mro__, python attributes, and more.
It is Copyright © 2005-2009 Shalabh Chaturvedi
http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#method-resolution-order

Read Full Post »

You may be aware of git add .
But did you know this:

git add .

adds all the files. Use with care (only after git status, for example).

git add -u .

adds and deletes all KNOWN files.
This is great if you added and removed or renamed files.

Read Full Post »

While converting a bunch of werkzeug code to Python 3.1, I ran into an issue with one of the bytes objects that was previously a string.
The line of code in question was originally this:

if value and value[0] == value[-1] == b’"’:

If value is something, and the first and last characters are [...]

Read Full Post »

Rather than use –all-databases, which will prevent you from being able to selectively restore any single database, consider the following:
Ideally, you should have a daily backup, with some history. It should be bulletproof (–force), it should be logged (>> …log), it should be compressed (| gzip), it should keep separate copies of each database, [...]

Read Full Post »

I use jQuery as the JavaScript library for most projects. It’s terribly convenient for selecting elements and processing them.
However, jQuery is not JavaScript, and there is a lot of things it cannot do. Rather than writing a separate set of functionality outside of jQuery, why not simply extend it on an application-per-application basis? It really [...]

Read Full Post »

Hello!
jQuery has a mouseout and a mouseleave event. The main difference is in how they handle child elements. Mouseout fires when the pointer moves into or out from child element, while mouseleave doesn’t.
This was causing a slight problem of having some menu’s close when the mouse encountered a link or other child element [...]

Read Full Post »

Maybe I should have known this about Python by now, but…
Little did I know (was wishing for it today), but there IS a way to specify that arguments MUST be keyword only.

>>> def foo(a,b,*,c,d):
…     print(a,b,c,d)

>>> foo(1,2,3,4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() takes exactly 2 positional arguments (4 given)

In [...]

Read Full Post »

Have been very busy at work lately.  We made the decision about a month ago to switch (most|all) new projects over to use Python 3 with Apache, mod_wsgi, and AppStruct.  You may know what the first 3 are, but the 4th??
Special thanks goes to Graham Dumpleton behind mod_wsgi, and James William Pye behind Python>>Postgresql.   [...]

Read Full Post »

Older Posts »