tkbe

November 13, 2009

windows7 :: auto-opening tree-view in Explorer

Filed under: windows7, timesavers, svn — tb @ 2:56 pm

I genuinely like the idea of the left pane in the Windows 7 Explorer window, although it’s mostly not very useful…

I don’t use Favorites since my working set of files is too big, but I’m assuming it’s useful for “someone”. I’m sure it’s possible to remove it by digging through the registry, but until it bothers me enough that I’ll go and google for a solution it just remains closed.

The Homegroup is apparently only useful if all your computers run Windows 7, and not so much if you have an Apple TV, an Eee Box, and a Debian Etch file server… :-(

The Computer Group is fine, except there’s no obvious way to hide items I cannot use, e.g. the “System Reserved” partition and the usb stick that is dedicated to ReadyBoost (I haven’t seen much effect, but I’m running a 10K RPM Raptor inside a box with 6GB RAM and an i7…). A big improvement from XP is that removable drives don’t show up unless they’re plugged in.

I skipped the Libraries group, which I actually find very useful — at least conceptually. When you have a lot of stuff, it tends to be in multiple places and adding multiple folders to a Library hides this nicely. It’s also a great way to present a G-rated version of your PC ;-)

A logical step for me was adding a “Work” Library, to give me a single starting point for all things work related. One of the first things I ran into was that if I included e:\websites\www.example.com, e:\websites\static.example.com and e:\dba, there was no easy way for me to right click those directories and get the correct context menu (you either get the context menu of the currently selected file inside the directory, or Windows 7 unhelpfully selects everything in the folder before invoking the right-click menu. Sure, I could just expand the Work Library node, but it’s a frustratingly small target to hit when you’re doing this hundreds of times a day.

There is a solution though. Right click on an empty area in the left pane, and select “Expand to current folder”. When you now navigate, using the nice big icons in the right pane, the tree-like directory structure in the left pane automatically opens to where you are — making it easy to right-click and SVN Commit.

django :: implementing reCAPTCHA in 5 easy steps

Filed under: django — tb @ 2:58 am

It turns out reCAPTCHA is very easy to implement :-)

Step #1: install the Python client:

CODE:
  1. easy_install recaptcha-client

Step #2: obtain public and private keys here: http://recaptcha.net/whyrecaptcha.html.

Step #3: Then create a small helper module, mycaptcha.py, for convenience and to keep your keys in one place...

PYTHON:
  1. import recaptcha.client.captcha as rc
  2.  
  3. public_key = 'your-public-key-from-step-2-goes-here'
  4. private_key = 'your-private-key-from-step-2-goes-here'
  5.  
  6. def displayhtml(use_ssl=False, error=None):
  7.     return rc.displayhtml(public_key, use_ssl, error)
  8.  
  9. def submit(request):
  10.     return rc.submit(
  11.         request.REQUEST.get('recaptcha_challenge_field',''),
  12.         request.REQUEST.get('recaptcha_response_field',''),
  13.         private_key,
  14.         request.META.get('REMOTE_ADDR', ''))

Step #4: create your Django view

PYTHON:
  1. def captcha_test_view(request):
  2.     import mycaptcha
  3.     error = None
  4.  
  5.     if request.method == 'POST':
  6.         response = mycaptcha.submit(request)
  7.         if response.is_valid:
  8.             return HttpResponseRedirect('success-url/')
  9.         else:
  10.             error = response.error_code
  11.            
  12.     recaptcha = captcha.displayhtml(error)
  13.  
  14.     return render_to_response('recaptcha_test.html', {'recaptcha':recaptcha})

Step #5: include the following inside the form element of your html...

HTML:
  1. <form method=POST ...>
  2.     {{ recaptcha|safe }}
  3.     ...
  4.     <input type=submit>
  5.   </form>

May 27, 2009

django :: date filter cheat sheet

Filed under: django — tb @ 12:48 pm

I don't seem able to memorize the list of format characters for the date filter, maybe because the documentation lists them in alphabetical order. I've created the cheat sheet below with an attempt at semantic grouping...

Time seconds s Seconds, 2 digits (with leading zeros).
minutes i Minutes (with leading zeros).
hours
(24 hr clock)
G Hour, 24-hour format without leading zeros.
H Hour, 24-hour format with leading zeros.
hours
(12 hr clock)
g Hour, 12-hour format without leading zeros.
h Hour, 12-hour format with leading zeros.
a a.m. or p.m.
A A.M. or P.M.
Date year y Year, 2 digits.
Y Year, 4 digits.
z Day of the year (0 - 365).
week W ISO-8601 week number.
w Day number of the week (0=Sunday, 6=Saturday).
month n Month number
m Month number, 2 digits (leading zeros)
b Month name, lower case, 3 characters.
M Month name, 3 characters.
F Month name
day j Day of the month
d Day of the month, 2 digits (leading zeros).
D Day name, 3 characters.
l Day name
z Day of the year (0 - 365)
w Day number of the week (0=Sunday, 6=Saturday).
misc. metainfo t Number of days in the given month.
L Leap year? (bool).
special formats r RFC 2822 formatted date..
U Seconds since the Unix Epoch (1970-01-01 00:00:00).
z Day of the year (0 - 365).
time zone O Difference to Greenwich time in hours.
Z Time zone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive..
T Time zone of this machine. ('EST', 'MDT').
English only S English ordinal suffix for day of the month (1st, 2nd)
P Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off if they're zero and the special-case strings 'midnight' and 'noon' if appropriate. Proprietary extension.
f Time, in 12-hour hours and minutes, with minutes left off if they're zero. (Proprietary extension.)
N Month abbreviation in Associated Press Style (proprietary extension).
« Previous PageNext Page »

Powered by WordPress