tkbe

November 26, 2009

butterflies and ajax.googleapis.com

Filed under: google, ajax, jQuery — tb @ 8:21 pm

In a recent debugging session i changed my include of the jQuery libraries, kindly hosted by Google, from

HTML:
  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

to

HTML:
  1. <script type="text/javascript" src="http://xajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Notice the extra "x" in front of the url? If you didn't, don't worry, Google didn't seem to notice it either... In fact, you can type anything you'd like in front of the word "ajax", including "butterflies-and-unicorns-ajax.googleapis.com".

I'm sure this is useful for something, and even if it isn't, who could object to Google embracing butterflies and unicorns ;-)

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>

Powered by WordPress