Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View reimund's full-sized avatar

Reimund Järnfors reimund

View GitHub Profile
@reimund
reimund / model.js
Last active January 4, 2016 20:59
Model base class. Features inheritance, automatically created accessors (get + set) and encapsulation of data. Setters are chainable.
var Model = function(attrs)
{
this.attrs = attrs;
for (var attr in attrs)
var tmp = function(name) {
this[attr] = function(x) {
if (arguments.length) {
this.attrs[name] = x;
return this;
@reimund
reimund / index.html
Created November 26, 2013 23:22
D3.js: Animate path point by index using custom interpolator.
<!DOCTYPE html>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<style>path { stroke: steelblue; stroke-width: 1; fill: none; }</style>
<body>
<script>
$(window).load(function() {
// Animate between these two straight lines.
var d0 = [[
@reimund
reimund / dict2xml.php
Last active December 16, 2015 18:49
Php port of my xml serializer.
<?php
function dict2xml($d, $root_node=null, $use_attr=true)
{
$wrap = (null == $root_node or is_plain_array($d)) ? false : true;
$root = (null == $root_node) ? 'objects' : $root_node;
$root_singular = ('s' == $root[strlen($root) - 1] and null == $root_node)
? substr($root, 0, strlen($root) - 1)
: $root;
$xml = '';
$end_tag = '';
@reimund
reimund / dict2xml.py
Last active December 25, 2023 06:09
Simple dictionary to xml serializer.
"""
Simple xml serializer.
@author Reimund Trost 2013
Example:
mydict = {
'name': 'The Andersson\'s',
'size': 4,
@reimund
reimund / settings.py
Last active December 15, 2015 07:59
Class based settings for Django. Set all common settings in BaseSettings, then create a subclass for each environment. Uses the environment variable DJANGO_ENV in order to decide which subclass it should use. I named the package "zettings" rather than "settings" to avoid import problems.
""" settings.py """
import sys, os
from zettings.base import *
sys.path.append(os.getcwd() + '/../')
ENV = os.environ.get('DJANGO_ENV', 'localdev')
# Import the right settings for this environment.
# DJANGO_ENV should be set to the name of a module which contains a
@reimund
reimund / UsefulListView.py
Created March 22, 2013 18:08
Allows passing extra_context to ListView.as_view().
from django.views.generic.list import ListView
class UsefulListView(ListView):
""" Allows passing extra_context to ListView.as_view(). """
extra_context = {}
def get_context_data(self, **kwargs):
context = super(UsefulListView, self).get_context_data(**kwargs)
context.update(self.extra_context)