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
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'] | |
}); |
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
from flask import Module, request, redirect, url_for, render_template, abort | |
from formalchemy import FieldSet | |
from example import db | |
from example import Service, User, Forum, Category, Topic, Post | |
mod = Module(__name__) | |
models = { |
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
#!/usr/bin/env python | |
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349 | |
print "Color indexes should be drawn in bold text of the same color." | |
colored = [0] + [0x5f + 40 * n for n in range(0, 5)] | |
colored_palette = [ | |
"%02x/%02x/%02x" % (r, g, b) | |
for r in colored |
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
// Make a single api call to meetup.com and grab event info for all (11) PyLadies locations. Create individual objects for each so that meetups can be added to each pyladies group's div on pyladies.com/locations page. | |
//helper function to discover event urls and make active links | |
//credit to http://www.sencha.com/forum/archive/index.php/t-12379.html for code this is based on | |
function create_urls(input) { | |
return input | |
.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '"$&" target="_blank"') | |
.replace(/([^\/])(www[\S]+(\b|$))/gim, '"http://$2" target="_blank"'); | |
} //end url parsing helper function |
A guide for reviewing code and having your code reviewed.
Peer code reviews are the single biggest thing you can do to improve your code - Jeff Atwood
Code review is an important part of a team's development process. It helps to:
- disseminate knowledge about the codebase/technology/techniques across teams
- increase awareness of the features being developed