import urllib
print urllib.quote_plus("http://www.yahoo.com/")
print urllib.quote_plus("Kruder & Dorfmeister")
Results:
http%3A%2F%2Fwww.yahoo.com%2F Kruder+%26+Dorfmeister
It is easy to be drawn to the urlencode function
in the Python
urllib module documentation. But for simple
escaping, only quote_plus, or possibly quote
is needed. I believe this is the appropriate solution to
Python urlencode annoyance and
O'Reilly's Amazon Hack #92.
For reference: Percent-encoding on Wikipedia
Read more...I had been using the following elisp to set my font in Emacs 23.
However, it did not work when creating new frames with C-x 5 2.
(if (>= emacs-major-version 23)
(set-default-font "Monospace-11"))
Here is how I set the font for all frames:
(if (>= emacs-major-version 23)
(modify-all-frames-parameters
'((font . "Monospace-11"))))
See the documentation for modify-all-frames-parameters for more information.
Read more...I've been using Twisted's Perspective Broker to manage networking for my Python program. Perspective Broker allows me to run a Python program on a remote machine and perform remote method calls on an object in the Python program. It also allows me to serialize objects and transfer them over TCP.
Once I got a Perspective Broker server and client running, I wanted
to create a "Twisted Application" and run it using twistd,
the
Twisted Daemon. Two major options are:
creating a .tac file and
creating a twistd plugin. Below, I show the steps I took to create
a ...
Despite the existence of the promising
waitForDeferred/deferredGenerator and the newer
inlineCallbacks, it appears there is no way to block
while waiting for a Deferred. Brian Granger
described the problem on the Twisted mailing list:
I have a function that returns a Deferred. I need to have the result of this Deferred returned in a (apparently) blocking/synchronous manner:glyph provided ... Read more...def myfuncBlocking(): d = myfuncReturnsDeferred() ... result = return resultI need to be able to call this function like:result = myfuncBlocking()The question is how to get the result out of the Deferred() and make it *look* like myfuncBlocking() has blocked.
Twisted is pretty
cool-- it is very powerful, but I haven't had the easiest time
learning it.
Here is a simple example that runs a couple functions
periodically (at different
rates) using LoopingCall.
For more information, here are the Twisted docs for LoopingCall.
from datetime import datetime
from twisted.internet.task import LoopingCall
from twisted.internet import reactor
def hyper_task():
print "I like to run fast", datetime.now()
def tired_task():
print "I want to run slowly", datetime.now()
lc = LoopingCall(hyper_task)
lc.start(0.1)
lc2 = LoopingCall(tired_task)
lc2.start(0.5)
reactor.run()
Results:
I like to run ...Read more...
Nikolay pointed me at beanstalkd, a lightweight, message queue service partially inspired by the popular caching system, memcached. It features a blocking "reserve" call so workers don't need to poll for new jobs. However, some might miss the data persistence since the queue is stored in memory. beanstalkd has client libraries in Erlang, Perl, PHP, Python, and Ruby. Of course, I will use the Python version, pybeanstalk. Simon Willison also found beanstalkd interesting. (Credit to him for some of the words above.)
Update 2008-10-13: For a helpful example on using beanstalkd and pybeanstalk see Parand's beanstalkd tutorial.
Here ...
Read more...Python 2.6 was released yesterday! This version aims to smooth the transition from Python 2.5 to Python 3.0 which is planned for release soon (currently available as a release candidate). Python 3.0 will be break backwards compatibility with the 2.x series. Python 2.6 is backwards compatible with 2.5. All the backwards compatible features of 3.0 have been backported to 2.6.
One of the new 2.6 features I'm particularly intersted in is the new multiprocessing module which has a similar interface to the threading module, but it uses processes instead ...
Read more...I have been using the emacs-snapshot package in Ubuntu Hardy.
However, when I tried to use
Tramp, I got an error message: Variable binding depth exceeds
max-specpdl-size. I couldn't find out how to fix this, and I
didn't want to use
Emacs 22.3 because it doesn't have Xft (anti-aliased fonts),
so I decided to live on the bleeding edge and install Emacs 23
from CVS. Besides the INSTALL and INSTALL.CVS files, I also used
theBlackDragon's article for reference.
Update 2008-10-09: I just found that Romain Francoise maintains an emacs-snapshot Debian package and it has ...
Read more...
aws
(4)
bison_flex
(1)
blogger
(4)
c
(10)
cardstore
(5)
colinux
(2)
concurrency
(8)
conkeror
(2)
cygwin
(17)
dell
(3)
django
(31)
eclipse
(30)
emacs
(18)
email
(1)
error
(11)
gnip
(1)
json
(1)
keyboard
(3)
linux
(31)
matplotlib
(5)
mercurial
(3)
openid
(1)
personal
(4)
preferences
(4)
pyqt
(18)
python
(88)
rails
(1)
ratpoison
(3)
recursion
(1)
rsync
(3)
ruby
(2)
sql
(10)
subversion
(4)
twisted
(5)
ubuntu
(33)
untagged
(7)
urxvt
(3)
vxworks
(26)
wmii
(3)