Archive for February, 2010
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/ [...]
