Skip to content

Instantly share code, notes, and snippets.

View pilt's full-sized avatar

Simon Pantzare pilt

View GitHub Profile
for swapr in SwapRequest.objects.all():
if len(swapr.swappossibility_set.all()) == 0:
swapr.delete()
SERIES #1
├── ITEM #1
├── ITEM #2
├── ITEM #3
SERIES #2
├── ITEM #1
├── ITEM #2
├── ITEM #3
When a SERIES is created, a given number of ITEMs should be
@pilt
pilt / runtornado.py
Created June 16, 2011 18:30
Django management command for running a Tornado server
# coding=utf-8
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
-- There is a monetary type but it is obsolete.
DROP DOMAIN IF EXISTS currency CASCADE;
CREATE DOMAIN currency AS numeric(10, 2);
DROP TABLE IF EXISTS products CASCADE;
CREATE TABLE products
(
id serial NOT NULL,
"name" character varying(50) NOT NULL UNIQUE,
CONSTRAINT product_pkey PRIMARY KEY (id)
@pilt
pilt / client.coffee
Created July 3, 2011 12:36
Getting "Uncaught TypeError: Object #<Object> has no method 'products'"
# The browser client.
now = window.now
Page = Backbone.Model.extend {}
Pages = Backbone.Collection.extend
mode: Page
window.pages = new Pages
Sidebar = Backbone.Model.extend {
loadPage: (page) ->
// Helper for history navigation. Links have
// href="#history-1" (or any other number).
$('a[href^="#history-"]').click(function() {
var idx = parseInt($(this).attr('href').split('-')[1], 10);
history.go(-idx);
return false;
});
@pilt
pilt / markup.html
Created July 24, 2011 19:19
Numerical input field enhancer in Coffeescript
<input type="text" class="num gte0">
@pilt
pilt / Gemfile
Created July 30, 2011 12:46
Incorporating Jammit with Django
source "http://rubygems.org"
gem "jammit"
gem "closure-compiler"
multipled = [3 * s for s in series]
coach_models = [
(health.models.HealthMessage, health.search_indexes.HealthMessageIndex),
(django.contrib.auth.models.User, health.search_indexes.UserIndex),
]
coach_site = haystack.sites.SearchSite()
coach_indexes = {}
def setup_signals(model):
index = coach_site.get_index(model)