This file contains hidden or 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 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 |
This file contains hidden or 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
| 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', |
This file contains hidden or 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
| """ | |
| 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 | |
| """ |
This file contains hidden or 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 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: |
This file contains hidden or 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 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()): |
This file contains hidden or 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
| handler = MailHandler() | |
| handler.register_address( | |
| address="[email protected]", | |
| secret="secret-key-from-cloudmailin", | |
| callback=create_post, | |
| ) | |
| urlpatterns = patterns('', | |
| url(r'^postbymail/$', mail_handler), | |
| ) |
This file contains hidden or 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 create_post(**message): | |
| author = User.objects.get(email=message['from']) | |
| title = message['subject'] | |
| content = message['plain'] | |
| p = Post.objects.create( | |
| author=author, | |
| title=title, |
This file contains hidden or 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
| 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', |
This file contains hidden or 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
| -- 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 |
This file contains hidden or 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 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: |