Skip to content

Instantly share code, notes, and snippets.

View insin's full-sized avatar
⚠️
Cannot read property 'status' of undefined

Jonny Buchanan insin

⚠️
Cannot read property 'status' of undefined
View GitHub Profile
@insin
insin / mdx_emoticons.py
Created February 8, 2011 01:21
Emoticon Extension for python-markdown
"""
Emoticon Extension for python-markdown
======================================
Converts defined emoticon symbols to images, with the symbols as their ``alt``
text. Requires python-markdown 1.6+.
Basic usage:
>>> import markdown
@insin
insin / gist:817860
Created February 9, 2011 04:07
SortHeaders for Django
"""
Handles creation of order_by criteria based on GET parameters and provides
context variables to be used when generating table header sort links which
respect the current sort field and direction, reversing the direction when
the same header is sorted by again.
"""
ORDER_VAR = 'o'
ORDER_TYPE_VAR = 'ot'
class SortHeaders:
@insin
insin / gist:817873
Created February 9, 2011 04:21
ImageURLField for Django forms
import urllib
from django import forms
from django.template.defaultfilters import filesizeformat
from django.utils.text import get_text_list
# Try to import PIL in either of the two ways it can end up installed
try:
from PIL import ImageFile as PILImageFile
except ImportError:
@insin
insin / gist:817906
Created February 9, 2011 04:59
TableSelectMultiple Widget for Django forms
"""
A widget for selecting from a list of Model instances using MultipleChoiceField
which renders a table row for each choice, consisting of a column for a checkbox
followed by a column for each item specified in item_attrs, which must specify
attributes of the objects passed as choices.
"""
from django.forms import CheckboxInput, SelectMultiple
from django.utils.encoding import force_unicode
from django.utils.html import escape
from django.utils.safestring import mark_safe
@insin
insin / gist:838187
Created February 22, 2011 03:50
js-forms & DOMBuilder on Node.js
> var forms = require("./js-forms");
> var TestForm = forms.formFactory({fields: function() {
... return {
... name: new forms.CharField(),
... age: new forms.IntegerField()
... };
... }});
>
> var f = new TestForm();
> f.toString()
@insin
insin / gist:849904
Created March 1, 2011 21:10
Tonight's coding mission: implement deep copying to kill some rather ugly boilerplate
// From...
var TestForm = forms.formFactory({
fields: function() {
return {
username: new forms.CharField(),
password: new forms.CharField({widget: forms.PasswordInput})
};
},
clean: function() {
if (this.cleanedData.username && this.cleanedData.password &&
@insin
insin / anon.py
Created March 7, 2011 14:43
Anonymise XML text by XPATH
# usage: anon.py input.xml output.xml
import random
import string
import sys
from lxml import etree
XPATHS = [
'/Path/To/Elements/*',
'/Another/Path/'
@insin
insin / testrequire1.js
Created March 22, 2011 11:12
Akshell modules - add to exports, don't replace it
repr([1, 2, 3, 4].map(function(i) { return require('./testrequire' + i).foo; }))
["bar", undefined, undefined, "bar"]
@insin
insin / comments.html
Created March 22, 2011 19:48
Akshell newforms demo
{% extends 'base.html' %}
{% block title %}Comments{% endblock %}
{% block content %}
<h1>Comments</h1>
<form action="." method="POST">
{% csrfToken %}
{% if form.nonFieldErrors.isPopulated %}
{{ form.nonFieldErrors }}
@insin
insin / ChromeContentScript.js
Created March 25, 2011 14:05
Chrome Extension compatibility for Greasemonkey's GM_getValue and GM_setValue
// Request settings from the extension's localStorage and kick things off
chrome.extension.sendRequest({type: "getprefs"}, function(response)
{
cachedSettings = response;
init();
});