Skip to content

Instantly share code, notes, and snippets.

View danielsokolowski's full-sized avatar

Daniel Sokolowski danielsokolowski

View GitHub Profile
@danielsokolowski
danielsokolowski / tablesort.js
Last active August 27, 2015 02:57 — forked from scopevale/fiddle.css
jsFiddle demo - Table Sort (vanilla JS)
function TableSort(oTableElement) {
this.tbl = oTableElement;
this.lastSortedTh = null;
if (this.tbl && this.tbl.nodeName == "TABLE") {
var headings = this.tbl.tHead.rows[0].cells;
for (var i=0; headings[i]; i++) {
if (headings[i].className.match(/asc|dsc/)) {
this.lastSortedTh = headings[i];
}
}
"use strict";
/*
* JQuery Substitute method allows for simple templating using JS Object dot notation.
* Contribute link: https://gist.github.com/danielsokolowski/0954fc2a767f441720b9
*
* @param strTemplate - string contain the replacement tokens
* @param objData - an Object represetnting your replacmenet values
*
* Example:
* var strTemplate = 'Hello {user.name}'
@danielsokolowski
danielsokolowski / obj_groups.py
Created July 30, 2012 17:34
Returns an html string node useful for providing a visual cue to the permission group required; django-guradian required.
from django import template, template
from django.contrib.auth.models import Group
from guardian.shortcuts import get_groups_with_perms
register = template.Library()
class ObjectGroups(template.Node):
"""
Returns an html string node useful for providing a visual cue to the
permission group required.
@danielsokolowski
danielsokolowski / gist:1352286
Created November 9, 2011 18:03
Updated: GeoJSON Serializer for GeoDjango (gis)
Unfortunately the built in Django JSON serialzer encodes GeoDjango GeometyrField as WKT text. This snippet extends django's serializer and adds support for GEOJson format.
Built in JSON serializer output:
[{"pk": 1, ... "geopoint": "POINT (-76.5060419999999937 44.2337040000000030)" ... }]
GeoJSON serializer ouput:
[{"pk": 1, ... "geopoint": {"type": "Point",
"coordinates": [-76.503296000000006, 44.230956999999997],
"__GEOSGeometry__": [
"__init__",
@danielsokolowski
danielsokolowski / tohexwebcolor.py
Created October 7, 2011 16:32
Django template tag to hash/map a value to a unique web color --- useful for coloring a list of database entries
import re
import hashlib
from django import template
register = template.Library()
class ToHexWebColorNode(template.Node):
def __init__(self, vartoconvert, varnametostoreas=False):
self.vartoconvert = template.Variable(vartoconvert)
self.varnametostoreas = varnametostoreas
@danielsokolowski
danielsokolowski / geojson_serializer.py
Created May 12, 2011 16:42
GeoJSON Serializer for GeoDjango (gis)
'''
Created on 2011-05-12
@author: Daniel Sokolowski
Extends django's built in JSON serializer to support GEOJSON encoding
Requirements:
Install and setup geodjango (django.contrib.gis)