More of a self-note…
…since this has some project-specific things in it, but a series of fairly useful VIm-formatted regexes to convert PHP into Python/Django syntax.
:'<,'>s/$\([a-z_]\+\) = (isset($_\(GET\|POST\)\['[a-z_]\+’\]) ? $[^ ]\+ : false);/\1 = request.\2.get(’\1′, None)/g
:’<,’>s/$\([a-z_]\+\) = array();/\1 = []/g
:’<,’>s/$\([a-z_]\+\) = array($/\1 = {/g
:’<,’>s/is_numeric($\([a-z_]\+\))/\1.isdigit()/g
:’<,’>s/$\([a-z_]\+\)\[\] = \(.*\);/\1.append(\2)/g
:’<,’>s/$\([a-z_]\+\)\[\([\'0-9a-z_]\+\)\] = \(.*\);/\1[\2] = \3/g
:’<,’>s/\<true\>/True/g
:’<,’>s/\<false\>/False/g
:’<,’>s/strlen($\([a-z_]\+\))/len(\1)/g
:’<,’>s/\(}\? \?\(el\)\(se\)/> \?\)\?if (\(.*\))\( \?{\)\?/\2if \4:/g
:’<,’>s/ \?|| \?/ or /g
:’<,’>s/ \?&& \?/ and /g
:’<,’>s/::/./g
:’<,’>s/;$//
:’<,’>s/!\$\?\([a-z_]\+\)/not \1/g
:’<,’>s/\$\([a-z_]\+\)/\1/g
:’<,’>s/->/./g
:’<,’>s/^\t\+}\n//
:’<,’>s/} else {/else:/g
:’<,’>s/’\([a-zA-Z_]\+\)’ => \([a-z_]\+\)/’\L\1′: \2/g
:’<,’>s/\([a-z]\)\([A-Z][a-z]\)/\1_\l\2/g
:’<,’>s/ \. / + /g
:’<,’>s/_SESSION\['user'\].\([a-zA-Z_]\+\)/request.user.\L\1/g
:’<,’>s/\([a-z_]\+\)\['\([a-zA-Z_]\+\)’] = /\1['\L\2'] = /g
:’<,’>s/user.permissions.\([a-z_]\+\)/user.has_perm(’\1′)/g
:’<,’>s/Utilities/utilities/g
Writing code that makes an entire group of people cry is <3. ![]()

2 Responses to “More of a self-note…”
Steve - February 12th, 2010
Oh, so NOW you’re using Django after mocking me for using it for so long.
Grump - February 12th, 2010
Die in a fire. <3
Leave a Reply