Thursday, April 28, 2011

Using {% url %}

Want to use the {% url %} template tags in Jinja2?

https://github.com/dcramer/coffin/blob/master/coffin/template/defaulttags.py

Want to use Jinja AND the Django template (for backwards compat with the admin screen)?

https://gist.github.com/472309

'delete' doesn't trigger keypress events in JavaScript

http://unixpapa.com/js/key.html


pecial Keys
KeyASCIIMozilla keycodesIE keycodesOpera keycodespseudo ASCII codesexceptions
Insert-45454545Konqueror: 0
Opera < 9.0: 0
Delete-46464646Konqueror: 127
Opera < 9.0: 0
Home-36363636Opera < 9.0: 0
End-35353535Opera < 9.0: 0
Page Up-33333333
Page Down-34343434
Function Keys
F1 to F12
-112 to 123112 to 123112 to 123112 to 123
Keypad Keys


Some browsers avoid this problem by not generating keypress events for special keys. A good case can be made that this is the right thing to do, since these keystrokes are arguably not character events. But such arguments are weakened by the arbitrariness of the division between normal and special keys. Why should the keyboard Backspace key have a keypress event, but not the keypad Delete key? Is Tab really fundamentally different than right arrow?
keypress events
event.keyCodeevent.whichevent.charCode
Internet Explorer (Windows)normal:ASCII codeundefinedundefined
special:no keypress events for special keys
Internet Explorer (Mac)normal:ASCII codeundefinedASCII code
special:no keypress events for special keys
Geckonormal:zeroASCII codeASCII code
special:Mozilla keycodezerozero
WebKit ≥ 525normal:ASCII codeASCII codeASCII code
special:no keypress events for special keys
WebKit < 525normal:ASCII codeASCII codeASCII code
special:extended ASCII codeextended ASCII codeextended ASCII code
Opera ≥ 10.50 (all platforms)normal:ASCII codeASCII codeundefined
special:Mozilla keycode, except keypad and branded keys give Opera keycodeszeroundefined
Opera ≥ 9.50 (all platforms)
Opera 7 (Windows)
normal:ASCII codeASCII codeundefined
special:Mozilla keycode, except keypad and branded keys give Opera keycodeszero for arrows, function keys, PageUp, PageDown
same as event.keyCode otherwise
undefined
Opera 8.0 to 9.27 (Windows)normal:ASCII codeASCII codeundefined
special:Opera keycodezero for arrows, function keys, PageUp and PageDown,
same as event.keyCode otherwise
undefined
Opera < 9.50 (Linux & Macintosh)normal:ASCII codeASCII codeundefined
special:Opera keycodezero for arrows, function keys, PageUp and PageDown,
same as event.keyCode otherwise
undefined
Konqueror 4.3normal:ASCII codeASCII codeASCII code
special:Pseudo-ASCII codePseudo-ASCII codezero
Konqueror 3.5normal:ASCII codeASCII codeASCII code
special:Pseudo-ASCII codezerozero
Konqueror 3.2normal:ASCII codeASCII codeundefined
special:no keypress events for special keys

Chrome Better Pop Up Block (v2.1.6) interferes with Hotmail

http://optimalcycling.com/other-projects/better-pop-up-blocker/

It is this popup blocker 2.16 that prevents from opening up Hotmail within Chrome browser.

With all my other extensions and plugins enabled or turned on, when the popup is enabled, email messages could not open Hotmail but could if it is disabled.

Surprisingly, Hotmail actually works very well with Chrome and is tacitly recommended by Microsoft to use!

Wednesday, April 20, 2011

Pylint and maximum recursion depth errors

Ever see these error messages in your pylint?

Exception RuntimeError: maximum recursion depth exceeded while calling a Python object

This bug was filed here: https://bugs.launchpad.net/pylint/+bug/456870 The solution seems to just upgrade Pylint using pip install instead of the Ubuntu Lucid package.

sudo apt-get remove pylint
sudo apt-get remove python-logilab-common
sudo pip install pylint

pylint --version
No config file found, using default configuration
pylint 0.23.0, 
astng 0.21.1, common 0.55.0
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3]

do...and and {} in Ruby

http://www.troubleshooters.com/codecorn/ruby/basictutorial.htm

Difference Between {} and do/end

As mentioned, there's one small difference between brace enclosed blocks and do/end enclosed blocks: Braces bind tighter. Watch this:

#!/usr/bin/ruby
my_array = ["alpha", "beta", "gamma"]
puts my_array.collect {
 |word|
 word.capitalize
}
puts "======================"
puts my_array.collect do
 |word|
 word.capitalize
end
[slitt@mydesk slitt]$ ./test.rb
Alpha
Beta
Gamma
======================
alpha
beta
gamma
[slitt@mydesk slitt]$

The braces bound tightly like this:

puts (my_array.collect {|word| word.capitalize})
Whereas do/end bind more loosely, like this:
puts (my_array.collect) do |word| word.capitalize} end

This issue is similar to the problem reported in http://stackoverflow.com/questions/5513531/ruby-do-end-vs-braces

Tuesday, April 19, 2011

Relative paths in PYTHONPATH breaks Nose tests

http://wingware.com/pipermail/wingide-users/2008-September/005878.html
What you're seeing is the affect of the current working directory being 
different when tests are run versus when the main debug file is run.  By 
default, the initial current working directory is the directory that the 
file run in in -- this applies to either the main debug file or the 
individual test files.
Another observation is that your HUDSON_HOME should be properly set too...otherwise Nose will not know to look for the right imports if you use $WORKSPACE in your PYTHONPATH.