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
<script type="text/javascript"> | |
$(window).load(function(){ | |
var hash_count = 0; | |
$('a[href="#"]').each(function(){ | |
if(!$(this).data("events")) hash_count++; | |
}); | |
$('head').append("<!-- " + hash_count + " links with # as their href -->"); | |
}); | |
</script> |
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
<script type="text/javascript"> | |
$(window).load(function(){ | |
var hash_count = 0; | |
$('a[href="#"]').each(function(){ | |
if(!$(this).data("events")) hash_count++; | |
}); | |
$('head').append("<!-- " + hash_count + " links with # as their href -->"); | |
}); | |
</script> |
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
""" | |
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. | |
""" |
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 |
OlderNewer