Skip to content

Instantly share code, notes, and snippets.

View djm's full-sized avatar

Darian Moody djm

View GitHub Profile
@djm
djm / itunes-to-feed-url-bookmarklet.js
Created April 22, 2012 17:05
Bookmarklet: Convert iTunes Store Podcast URL into actual feed URL
(function() {
/* Bookmarklet that displays the actual podcast feed
* URL when ran on an iTunes store page for a podcast.
*
* Simply grabs the Artist ID from the URL and does
* an iTunes Store API lookup to get the hidden (original)
* podcast feed URL (whatever format that may be in).
*
* @author: Darian Moody <mail@djm.org.uk>
* @date: Working as of Sun.22.Apr.2012
@djm
djm / cron
Last active December 17, 2015 09:58
Cron one liners for virtualenv based django management commands
# I mean this:
* */12 * * * /path/to/virtualenv/bin/python /path/to/django/project/manage.py cleanup
# over this:
* */12 * * * source /path/to/virtualenv/bin/activate; /path/to/django/project/manage.py cleanup
@djm
djm / retrieve_dict.py
Last active December 30, 2015 00:19
Retrieve a list of a Scrapy project's spiders via Python
# Works on Scrapy v0.20
from scrapy.crawler import Crawler
from scrapy.utils.project import get_project_settings
def get_spiders():
""" Retrieves a dict of the spiders classes available to the current
scrapy keyed by their string-name.
"""
settings = get_project_settings()
@djm
djm / human_readable.py
Last active January 3, 2016 10:59
Convert Programming Cased strings to a Human Readable one
import re
def camelcase_to_human_readable(camel_cased_string):
""" Converts a string from CamelCase to Human readable.
e.g SuperBadRobot -> Super Bad Robot
"""
return ' '.join(re.findall("([A-Z][^A-Z]*)", camel_cased_string)).strip()
@djm
djm / dl.py
Created July 19, 2014 13:03
Download all from imgur embed URL
import os
import sys
from os.path import basename, splitext
from urlparse import urlparse
import requests
from bs4 import BeautifulSoup
def extract_full_size_url_from_tag(image_tag):
@djm
djm / gae_shell.py
Created September 28, 2014 12:20
Google App Engine Development Shell
#!/usr/bin/env python -i
"""
A local interactive IPython shell for Google App Engine on Mac OSX.
Usage:
cd /to/project/folder/with/app.yaml
python gae_shell.py
Notes:
@djm
djm / Dockerfile
Created October 20, 2014 21:03
Simple docker/fig setup for Django
FROM python:2.7
# Force stdin, stdout and stderr to be totally unbuffered.
ENV PYTHONUNBUFFERED 1
# For Pillow to have freetype support.
RUN ln -s /usr/include/freetype2 /usr/include/freetype
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
@djm
djm / closures_ftw.py
Created February 26, 2015 02:57
Prefer closures over classes keeping state
# Bad
class Join(object):
"""
>>> join_by_commas = Join(',')
>>> join_by_commas(['o', 'm', 'g'])
'o,m,g'
"""
def __init__(self, separator=u' '):
self.separator = separator
@djm
djm / aws.lambda.upload.error.output
Last active July 4, 2020 07:19
Node Lambda Upload Error: "Cross-account pass role is not allowed"
Reading zip file to memory
Uploading zip file to AWS Lambda eu-west-1 with parameters:
{ FunctionName: 'xxx-staging-1-0-0',
FunctionZip: <Buffer 50 478 0b 00 ...>,
Handler: 'index.handler',
Mode: 'event',
Role: 'arn:aws:iam::xxx:role/xxx',
Runtime: 'nodejs',
Description: 'Resizes images for the xxx project.',
MemorySize: '512',
@djm
djm / chunk.js
Created August 19, 2015 19:49
Javascript: chunk an ES6 Map into an Array of similar sized Maps
export function chunkMap (map, chunkSize) {
const chunkedMaps = []
const mapAsArray = Array.from(map)
for (var i = 0; i < map.size; i += chunkSize) {
let chunked = mapAsArray.slice(i, i + chunkSize)
chunkedMaps.push(new Map(chunked))
}
return chunkedMaps
}