Skip to content

Instantly share code, notes, and snippets.

View jcarbaugh's full-sized avatar
🍳

Jeremy Carbaugh jcarbaugh

🍳
View GitHub Profile
@jcarbaugh
jcarbaugh / nestedkeys.py
Created September 2, 2011 19:16
Create a nested dict from a dotted-key dict
def rejigger(src):
dst = {} # dict to hold new structure
# iterate over keys and values in source dict
for key, value in src.iteritems():
set_value(dst, key.split('.'), value)
return dst
@jcarbaugh
jcarbaugh / html5spec.py
Created August 26, 2011 18:12
Can a div be used inside a figure in HTML5? Based on an older version of the spec.
METADATA_ELEMENTS = ('command', 'link', 'meta', 'noscript', 'script', 'style')
PHRASING_ELEMENTS = ('a', 'abbr', 'area', 'audio', 'b', 'bdo', 'br', 'button',
'canvas', 'cite', 'code', 'command', 'datalist', 'del', 'dfn', 'em', 'embed',
'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark',
'meter', 'noscript', 'object', 'output', 'progress', 'q', 'ruby', 'samp',
'script', 'select', 'small', 'span', 'strong', 'sub', 'sup', 'textarea',
'time', 'var', 'video')
FLOW_ELEMENTS = ('address', 'article', 'aside', 'blockquote',
@jcarbaugh
jcarbaugh / tumblr2s3.py
Created August 26, 2011 17:48
Generate an RSS feed from your Tumblr dashboard and push it to S3.
"""
Create an RSS feed from your Tumblr dashboard and write to S3.
Run with -x command to write to stdout instead of pushing to S3.
Requirements:
boto
python-s3file
PyRSS2Gen
"""
@jcarbaugh
jcarbaugh / tweets.py
Last active September 26, 2015 23:08
Very simple, basic access to the Twitter API
"""
A very simple client for basic access to the Twitter API.
import tweets
client = tweets.TwitterClient(CONSUMER_KEY, CONSUMER_SECRET)
client.get_access_token() # complete authentication and enter PIN
client.get('statuses/home_timeline')
Requirements:
@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()):
@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="[email protected]",
secret="secret-key-from-cloudmailin",
callback=create_post,
)
urlpatterns = patterns('',
url(r'^postbymail/$', mail_handler),
)
@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,
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',
-- 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
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: