Skip to content

Instantly share code, notes, and snippets.

View jeremyjbowers's full-sized avatar

Jeremy Bowers jeremyjbowers

View GitHub Profile
import urlparse
import oauth2 as oauth
consumer_key = ''
consumer_secret = ''
request_token_url = 'http://www.tumblr.com/oauth/request_token'
access_token_url = 'http://www.tumblr.com/oauth/access_token'
authorize_url = 'http://www.tumblr.com/oauth/authorize'
class ReloaderEventHandler(FileSystemEventHandler):
"""
Listen for changes to modules within the Django project
On change, reload the module in the Python Shell
Custom logic required to reload django models.py modules
Due to the singleton AppCache, which caches model references.
For those models files, we must clear and repopulate the AppCache
"""
def __init__(self, *args, **kwargs):
@jeremyjbowers
jeremyjbowers / tumblr_aggregates.py
Last active December 11, 2015 06:19
Get counts by voting type.
import json
import requests
from collections import defaultdict
base_url = 'http://api.tumblr.com/v2/blog/inauguration2013.tumblr.com/posts/photo'
key_param = '?api_key=Cxp2JzyA03QxmQixf7Fee0oIYaFtBTTHKzRA0AveHlh094bwDH'
limit_param = '&limit=20'
limit = 20
new_limit = limit
@jeremyjbowers
jeremyjbowers / tumblr_output_posts.py
Created January 17, 2013 20:22
This outputs tumblr posts to JSON and CSV. Requires beautifulsoup4, csvkit and requests.
#!/usr/bin/env python
"""
Code which generates tumblr post outputs -- in CSV and JSON.
"""
import json
from bs4 import BeautifulSoup
from csvkit.convert import convert
import requests
@jeremyjbowers
jeremyjbowers / uwsgi.conf
Created February 15, 2013 15:53
My favorite (current) uwsgi config
description "uWSGI server for APP_NAME"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
env ENV_THINGY=my_env
script
/usr/local/bin/uwsgi \

Where people struggle learning Django

Over the last 3 years or so I've helped a bunch of companies, small and large, switch to Django. As part of that, I've done a lot of teaching Django (and Python) to people new to the platform (and language). I'd estimate I've trained something around 200-250 people so far. These aren't people new to programming — indeed, almost all of them are were currently employed as software developers — but they were new to Python, or to Django, or to web development, or all three.

In doing so, I've observed some patterns about what works and what doesn't. Many (most) of the failings have been my own pedagogical failings, but as I've honed my coursework and my skill I'm seeing, time and again, certain ways that Django makes itself difficult to certain groups of users.

This document is my attempt at organizing some notes around what ways different groups struggle. It's not particularly actionable — I'm not making any arguments about what Django should or shouldn't do (at least

@jeremyjbowers
jeremyjbowers / upload.html
Created February 20, 2013 21:25
A form which will upload to an Amazon S3 bucket.
<html>
<head>
<title>Upload a file to S3</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<h1>Upload a file to S3</h1>
<form action="http://bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<input id="uploadedkey" type="hidden" name="key" />
@jeremyjbowers
jeremyjbowers / scrape.py
Last active December 14, 2015 10:28
A basic scraper to grab information from the internet. Requires requests, beautifulsoup4.
# -*- coding: utf-8
from bs4 import BeautifulSoup
import requests
import re
def scrape_index_page():
"""
Returns a list of URLs to scrape.
@jeremyjbowers
jeremyjbowers / skelton.py
Created March 13, 2013 13:25
Trying to solve Chad Skelton's SSL issues.
#!/usr/bin/env python
"""
Start up a virtualenv and make sure you have the following libraries.
pip install requests==1.1.0 urllib3==1.5 wsgiref==0.1.2
"""
import requests
url = 'https://eservice.pssg.gov.bc.ca/LRA/'
r = requests.get(url, verify=False)
print r.content
@jeremyjbowers
jeremyjbowers / skelton2.py
Created March 13, 2013 14:43
Scraping example for Chad Skelton. This one means no mechanize required.
"""
pip install beautifulsoup4==4.1.3 requests==1.1.0
"""
import requests
from bs4 import BeautifulSoup
url = 'https://eservice.pssg.gov.bc.ca/LRA/reporting/public/activeterm.do?method=get'
data = {
'registrationRole': 'all',