This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_form_fields(self, soup): | |
"Turn a BeautifulSoup form in to a dict of fields and default values" | |
fields = {} | |
for input in soup.findAll('input'): | |
# ignore submit/image with no name attribute | |
if input['type'] in ('submit', 'image') and not input.has_key('name'): | |
continue | |
# single element nome/value fields | |
if input['type'] in ('text', 'hidden', 'password', 'submit', 'image'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Traditional - 9 lines | |
def view(request, template): | |
if request.method == "POST": | |
form = FormCls(request.POST) | |
if form.is_valid(): | |
form.save() | |
return HttpResponseRedirect("") | |
else: | |
form = FormCls() | |
return render_to_response(template, {"form": form}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A pydoc that can read modules using Django. | |
#!/usr/bin/env python | |
from django.conf import settings | |
if not settings.configured: | |
settings.configure() | |
import pydoc | |
if __name__ == "__main__": | |
pydoc.cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XMonad | |
import XMonad.Config.Gnome | |
import XMonad.Util.EZConfig | |
import XMonad.Actions.CycleWS | |
main = xmonad $ gnomeConfig { | |
terminal = "gnome-terminal" | |
, modMask = mod4Mask | |
} | |
`additionalKeysP` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# View remote html on your local box | |
# | |
# The following snippet will open a local firefox | |
# with the contents of a remote html file. The | |
# assumption is you have an ssh server running | |
# locally. It would also help if you have ssh keys | |
# set coming and going. | |
ssh -R 10999:localhost:22 justinlilly.com | |
TRANS_FILE='/tmp/myfile.html' ssh localhost -p 10999 "scp justinlilly.com:$TRANS_FILE /tmp/tmp.html && firefox --display=:0.0 file:///tmp/tmp.html; rm /tmp/tmp.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Escaped string issue. | |
encoded_str = "Caf\\xc3\\xa9" | |
encoded_str.replace('\\\\', '\') | |
# returns: "Caf\\xc3\\xa9" | |
encoded_str.replace('\\', '') | |
# returns: "Cafxc3xa9" | |
import re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Packages required to get emacs to compile will all optional stuff. (all yes's on ./configure) | |
sudo apt-get install libjpeg62-dev libtiff4-dev libgif-dev libgtk2.0-dev libxpm-dev libpng12-dev xaw3dg-dev librsvg2-dev libgconf2-dev libgpm-dev libdbus-1-dev libotf-dev libm17n-dev libncurses5-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestActiveField(object): | |
models_to_test = ['Model1', 'Model2', 'foo'] | |
def test_valid_choice(self): | |
for model in self.models_to_test: | |
yield self.check_valid_choice_for_active_field, model | |
def check_valid_choice_for_active_field(self, model): | |
# implement test logic here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.paths.unshift(__dirname + '/../lib'); | |
var sys = require('sys'); | |
var irc = require('irc'); | |
var http = require('http'); | |
var fs = require('fs'); | |
var bot = new irc.Client('irc.freenode.net', 'iShouldChangeBotName', { | |
channels: ['#node.js'] | |
}); |