Skip to content

Instantly share code, notes, and snippets.

View jcarbaugh's full-sized avatar
🍳

Jeremy Carbaugh jcarbaugh

🍳
View GitHub Profile
@jcarbaugh
jcarbaugh / wsgiqueue.py
Created April 4, 2009 04:13
provides a HTTP and WSGI interface to memcached
#!/usr/bin/env python
import memcache
HOST = '127.0.0.1'
PORT = 11211
class QueueDoesNotExist(Exception):
pass
def application(environ, start_response):
@jcarbaugh
jcarbaugh / fsql.py
Created April 23, 2009 18:12
convert a MySQL dump into SQLite
#!/usr/bin/env python
# Convert a mysql dump into a sqlite-compatible format.
# I wrote this for just one script... no guarantess that it will work with others...
# python fsql.py < mysqldump.sql > readyforsqlite.sql
import re
import sys
content = sys.stdin.read()
@jcarbaugh
jcarbaugh / lddl.py
Created May 14, 2009 18:10
download lobbying disclosures from US House of Representatives
#!/usr/bin/env python
# Copyright (c) 2009, Jeremy Carbaugh
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
@jcarbaugh
jcarbaugh / compatibility.py
Created May 18, 2009 17:43
Django middleware for X-UA-Compatible HTTP header
# Copyright (c) 2009, Sunlight Foundation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
from django.contrib.auth.models import User
import base64
class HTTPBasicAuthMiddleware(object):
def process_request(self, request):
authorization = request.META.get('HTTP_AUTHORIZATION', None)
if authorization:
-- Get a URL from the clipboard
set longURL to the clipboard
-- The command to get the shortened URL from the Internets (choose 1 method)
set cmd to "curl http://colossalurl.com/api/colossify/?url=" & longURL
-- Run the curl command and set the new URL to the clipboard
set shortURL to do shell script cmd
set the clipboard to shortURL as text
MEDIA_STATIC_ROOT = os.path.join(PROJECT_PATH, '..', 'site_media', 'static')
MEDIA_STATIC_URL = '/site_media/static/'
MEDIA_ROOT = os.path.join(PROJECT_PATH, os.pardir, '..', 'site_media', 'dynamic')
MEDIA_URL = '/site_media/dynamic/'
MEDIASYNC = {
'MEDIA_ROOT': MEDIA_STATIC_ROOT,
'MEDIA_URL': MEDIA_STATIC_URL,
'BACKEND':'mediasync.backends.s3',
@jcarbaugh
jcarbaugh / gist:885854
Created March 24, 2011 20:55
create_post method for posting by email with django-cloudmailin
def create_post(**message):
author = User.objects.get(email=message['from'])
title = message['subject']
content = message['plain']
p = Post.objects.create(
author=author,
title=title,
@jcarbaugh
jcarbaugh / gist:885876
Created March 24, 2011 21:01
MailHandler registration for posting by email with django-cloudmailin
handler = MailHandler()
handler.register_address(
address="000000000000000000@cloudmailin.com",
secret="secret-key-from-cloudmailin",
callback=create_post,
)
urlpatterns = patterns('',
url(r'^postbymail/$', mail_handler),
)
@jcarbaugh
jcarbaugh / challengegov.py
Created August 9, 2011 15:05
Get a screenshot for each challenge on challenge.gov
from lxml.html import parse
import re
import subprocess
import urllib2
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
def slugify(text, delim=u'-'):
result = []
for word in _punct_re.split(text.lower()):