Skip to content

Instantly share code, notes, and snippets.

View justinabrahms's full-sized avatar

Justin Abrahms justinabrahms

View GitHub Profile
<script type="text/javascript">
$(window).load(function(){
var hash_count = 0;
$('a[href="#"]').each(function(){
if(!$(this).data("events")) hash_count++;
});
$('head').append("&lt;!-- " + hash_count + " links with # as their href --&gt;");
});
</script>
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'):
# 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})
We couldn’t find that file to show.
@justinabrahms
justinabrahms / djpydoc
Created June 25, 2009 11:45 — forked from ask/djpydoc
# 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()
import XMonad
import XMonad.Config.Gnome
import XMonad.Util.EZConfig
import XMonad.Actions.CycleWS
main = xmonad $ gnomeConfig {
terminal = "gnome-terminal"
, modMask = mod4Mask
}
`additionalKeysP`
# 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"
"""
The HOSTMAP variable is a dictionary of lists. The keys represent
roles of a server, the values represent the hostnames of machines that
fill those roles. If you are reading this, you likely know what you're
doing. If you don't know what you're doing, you probably want to put
your hostname into local_dev. Ensure it has a comma at the end, and
the hostname is a string.
You can get your hostname by typing `hostname` into a terminal.
"""
# Escaped string issue.
encoded_str = "Caf\\xc3\\xa9"
encoded_str.replace('\\\\', '\')
# returns: "Caf\\xc3\\xa9"
encoded_str.replace('\\', '')
# returns: "Cafxc3xa9"
import re