Skip to content

Instantly share code, notes, and snippets.

View hanleybrand's full-sized avatar

Peter Hanley hanleybrand

View GitHub Profile
@hanleybrand
hanleybrand / bezLipsKuhlr.java
Created August 30, 2011 15:03
bezElips source
import processing.core.*;
import processing.xml.*;
import java.applet.*;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
import java.awt.Image;
@hanleybrand
hanleybrand / gist:2316346
Created April 6, 2012 02:57
Mac httpd.conf for localhost mdid3
## Append to bottom of your httpd.conf (or wherever you want to put it)
WSGIScriptAlias / /Users/username/Dev/mdid3/django_virtualenv.wsgi
## Server setup
alias /static/admin/ /Users/username/mdid3/django/contrib/admin/media/
alias /static/ /Users/username/mdid3/rooibos/static/
@hanleybrand
hanleybrand / gist:2764629
Created May 21, 2012 20:55
ZURB Joyride - reset 'count' when tour is finished
/* problem: when ZURB's Joyride tour ends, if the user causes it to run again, the
'count' seems to be messed up
solution: the plugin creates divs with ids in the pattern: 'joyRidePopup' + index
and then iterates through them - running the iteration again recreates the divs &
re-runs and gets confused. So you use postRideCallback (one of the options, see
http://www.zurb.com/playground/jquery-joyride-feature-tour-plugin - step 5 for more info)
to remove those divs when the ride ends
this GIST shows how to bind joyride to a 'HELP' button that will trigger the tour when clicked.
@hanleybrand
hanleybrand / gist:3313903
Created August 10, 2012 12:32
import slideshow via mdid3 api
__author__ = 'hanleybrand'
# thank you http://www.doughellmann.com/PyMOTW/json/
# http://www.voidspace.org.uk/python/articles/cookielib.shtml
import os
import json
import urllib, urllib2, cookielib
import tempfile
cj = cookielib.LWPCookieJar()
COOKIEFILE = 'cookies.lwp'
@hanleybrand
hanleybrand / loggedin.html
Created October 12, 2012 20:18 — forked from Miserlou/loggedin.py
Django Filter By Users Last Logged In
{%for u in users%}
{{u}} - {{u.last_login}}<br />
{% endfor %}
@hanleybrand
hanleybrand / record example.py
Created October 15, 2012 14:46
A simplified listing of the Record model from rooibos/data/models.py
class Record(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
name = models.SlugField(max_length=50, unique=True)
parent = models.ForeignKey('self', null=True, blank=True)
source = models.CharField(max_length=1024, null=True, blank=True)
manager = models.CharField(max_length=50, null=True, blank=True)
next_update = models.DateTimeField(null=True, blank=True)
owner = models.ForeignKey(User, null=True, blank=True)
@hanleybrand
hanleybrand / gist:3903264
Created October 17, 2012 01:43
Chooser (username entry on django command line)
from django.contrib.auth.models import User
# assumes an already logged in user,
# with their username captured in a variable
target_user = chooser(raw_input("enter the username that will own the slideshow being created. Press Enter for %s " % username), username)
def chooser(anotherUser, me, inception = 0):
""" Given raw input and an already authenticated user, returns a valid user name
@hanleybrand
hanleybrand / iTunesU.py
Created November 7, 2012 22:15
Script that generates an html file that will log a credentialled user into iTunesU (obvs you supply your own credentials)
#!/usr/bin/python
import urllib
import urllib2
import time
import hashlib
import hmac
# I was fixing iTunesU.py as per
# http://www.maclearning.org/articles/40/fixing-apple-s-i-tunes-u-python-s
# and I decided to try to make it a tiny bit more pythonic, as in
@hanleybrand
hanleybrand / Step 1.py
Created November 21, 2012 18:48
Here's how a thumbnail is requested
# rooibos/storage/views.py
###
# a request for /media/thumb/{media.pk}/{record.id}/
# handled by url(r'^thumb/(?P<id>\d+)/(?P<name>[-\w]+)/$', record_thumbnail, name='storage-thumbnail'),
# record_thumbnail and its decorator below
# it calls get_thumbnail_for_record from rooibos/storage/__init__.py
def add_content_length(func):
def _add_header(request, *args, **kwargs):
response = func(request, *args, **kwargs)

jQuery Deferred

Escaping from callback Hell

jQuery.Deferred implements CommonJS Promises/A

It's a chainable utility object that can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.