Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / gist:476058
Created July 14, 2010 20:57
from django.core.exceptions import ValidationError
from django.db.models import Field, CharField
__all__ = ['MultiColumnField']
try:
from hashlib import md5
except ImportError:
from md5 import new as md5
console.log('Loading function');
const https = require('https');
const url = require('url');
const slack_url = 'https://hooks.slack.com/services/...';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {
'Content-Type': 'application/json'
};
@zeke
zeke / mozilla-npm-config.sh
Last active January 3, 2016 06:59
A .npmrc file for use when the public npm registry is down.
# npm mirroring, courtesy @jbuck and Mozilla.
# See https://github.com/jbuck/npm-readonly-mirror
curl npmrc.zeke.xxx >> .npmrc
git add .npmrc
git commit -m "mozilla .npmrc"
git push heroku master
class QuerySetDoubleIteration(Exception):
"A QuerySet was iterated over twice, you probably want to list() it."
pass
# "Skinny" here means we use iterator by default, rather than
# ballooning in memory.
class SkinnyManager(Manager):
def get_query_set(self):
return SkinnyQuerySet(self.model, using=self._db)
import simplejson as json
import lxml
class objectJSONEncoder(json.JSONEncoder):
"""A specialized JSON encoder that can handle simple lxml objectify types
>>> from lxml import objectify
>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
>>> objectJSONEncoder().encode(obj)
'{"price": 1.5, "author": "W. Shakespeare"}'
"""
@lox
lox / cloudformation_tail.sh
Created August 3, 2015 04:08
A bash script to tail CloudFormation events
#!/bin/bash -eu
# Show all events for CF stack until update completes or fails.
cf_tail() {
local stack="$1"
local current
local final_line
local output
local previous
until echo "$current" | egrep -q "${stack}.*_(COMPLETE|FAILED)" ; do
@JeffreyWay
JeffreyWay / gist:1525217
Created December 27, 2011 21:29
Instant Server for Current Directory
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
@mrspeaker
mrspeaker / README
Created November 2, 2011 11:04
AI Class playlist generator
These are the scripts I use to create the playlists for the AI Class (available here: http://www.mrspeaker.net/2011/10/26/ai-class-playlists/). It's not pretty, but it works. I put them up here due to popular demand.
The first stage is to grab the video list HTML from YouTube and extract/sort the videos. This is done with the Video_ID_scraper.html file (instructions there).
Next, paste the video info into the YouTube_Playlist_Uploader.py script and it generates the playlist. It relies on the GData APIs so you need a dev key etc.
Any questions to mrspeaker@gmail.com
@samuelclay
samuelclay / image_dominant_color.py
Created April 14, 2011 01:21
Algorithm to find the dominant color in an image.
from PIL import Image
import scipy
import scipy.cluster
from pprint import pprint
image = Image.open('logo_newsblur_512.png')
NUM_CLUSTERS = 15
# Convert image into array of values for each point.
ar = scipy.misc.fromimage(image)
@davidnunez
davidnunez / gist:1404789
Created November 29, 2011 13:20
list all installed packages in android adb shell
pm list packages -f