tkbe

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).

March 12, 2009

cool :: AJAX APIs Playgroun

Filed under: google, ajax — tb @ 10:31 pm

I just stumbled upon the AJAX APIs Playground (http://code.google.com/apis/ajax/playground/). It’s a site with only one purpose: interactive examples of how to use Google Ajax APIs. Better, by far, than countless pages of documentation ;-)

March 8, 2009

emacs :: my first emacs-lisp function (!)

Filed under: emacs — tb @ 1:31 am

I've been finding myself in a tricky situation a lot lately: I'm programming along, and suddenly I realize that the thing I'm writing really should be factored out and named with a variable.

PYTHON:
  1. page.calendar.add(Employee.username(...

"whoops, I'm going to refer to this employee again... I should have written:"

PYTHON:
  1. emp = Employee.username(request.user.username)
  2.    page.calendar.add(emp, ...

What to do? Should I finish the line I'm on and then insert a line above (from experience I know my memory is so bad I'm likely to have forgotten by the time I get to the end of the line); or should I navigate up, insert the line and then try to find my way back to where I was.

What I really needed was to be able to press C-return and magically be transported to a fresh, new, blank and properly indented line above my point. Then I could use the standard C-u C-spc to get back to where I started... After a couple of hours of reading the fine manual, here's what I came up with:


(defun insert-and-indent-line-above ()
  (interactive)
  (push-mark)
  (let* ((ipt (progn (back-to-indentation) (point)))
   (bol (progn (move-beginning-of-line 1) (point)))
   (indent (buffer-substring bol ipt)))
    (newline)
    (previous-line)
    (insert indent)))
 
(global-set-key [ (control return) ] 'insert-and-indent-line-above)

it brought me great satisfaction (even though I realize there is probably a much simpler and more elegant way to do this).

Next Page »

Powered by WordPress