Skip to content

Instantly share code, notes, and snippets.

View teserak's full-sized avatar
🏠
Working from home

Konrad Rymczak teserak

🏠
Working from home
View GitHub Profile
@ejucovy
ejucovy / graphael-linechart-legend.js
Created June 24, 2010 16:15
manually building a legend for a g.raphael linechart
raph = Raphael([..]);
chart = raph.g.linechart([..]);
var labels = ["first variable", "second variable", "third variable"];
chart.labels = raph.set();
var x = 15; var h = 5;
for( var i = 0; i < labels.length; ++i ) {
var clr = chart.lines[i].attr("stroke");
chart.labels.push(raph.set());
chart.labels[i].push(raph.g["disc"](x + 5, h, 5)
@patrys
patrys / abstract.py
Created September 17, 2010 11:59
Parametrized apps for Django
class AbstractMixin(object):
_classcache = {}
@classmethod
def contribute(cls):
return {}
@classmethod
def construct(cls, *args, **kwargs):
attrs = cls.contribute(*args, **kwargs)
var express = require('express');
var app = express.createServer();
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyDecoder());
app.use(express.logger());
});
@niran
niran / mail.py
Created February 23, 2011 19:33
Multiple email connections in Django
from django.conf import settings
import django.core.mail
class MissingConnectionException(Exception):
pass
def get_connection(label=None, **kwargs):
if label is None:
label = getattr(settings, 'EMAIL_CONNECTION_DEFAULT', None)
@toastdriven
toastdriven / user1.py
Created April 12, 2011 17:27
First example uses a ``OneToOne`` profile, the second uses the traditional Django profile bits.
from django.contrib.auth.models import User
# from tastypie.authentication import ApiKeyAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie import fields
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from core.api.authentication import OpenReadApiKeyAuthentication
class UserResource(ModelResource):
bio = fields.CharField(attribute='profile__bio', null=True)
@liamcurry
liamcurry / models.py
Created May 5, 2011 14:58
Django Snippets
from django.db import models
class TimeAwareModel(models.Model):
created_on = models.DateTimeField(editable=False, auto_now_add=True)
updated_at = models.DateTimeField(editable=False, auto_now=True)
class Meta:
abstract = True
@hitezh
hitezh / passenger_wsgi.py
Created June 13, 2011 15:47
Bottle on Dreamhost
# Detailed explanation at http://hitesh.in/2011/running-a-bottle-py-app-on-dreamhost/
#1. Add current directory to path, if isn't already
import os, sys
cmd_folder = os.path.dirname(os.path.abspath(__file__))
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
import bottle
from bottle import route, run
@armonge
armonge / fields.py
Created July 18, 2011 14:41
A Django custom modelfield, formfield and formwidget to select and save a set of geographic coordinates using Google Maps
class GoogleMapMarker(object):
def __init__(self, latitude, longitude):
self.latitude = latitude
self.longitude = longitude
def __unicode__(self):
return '%f,%f'%(self.latitude, self.longitude)
def __len__(self):
return len(self.__unicode__())
@erikankrom
erikankrom / accounts-models.py
Created September 5, 2011 22:36
Multiple Profiles for Internal/External Users
from django.db import models
from django.contrib.auth import User
from mycompany.models import Client
from userprofiles.models import Profile
class External(Profile):
#External-specific models
client = models.ForeignKey(Client)
def __unicode__(self):
@leah
leah / json-response.py
Created October 5, 2011 19:08
JSONResponse classes
import re
import simplejson
from django.http import HttpResponse
from django.conf import settings
class JSONResponse(HttpResponse):
def __init__(self, request, data):
indent = 2 if settings.DEBUG else None