Skip to content

Instantly share code, notes, and snippets.

View adriaant's full-sized avatar

Adriaan Tijsseling adriaant

View GitHub Profile
@kristopherjohnson
kristopherjohnson / subclassAndProtocol.swift
Last active August 29, 2015 14:04
Function that takes an argument that must be a subclass of a specified class, and that subclass must implement a specified protocol
protocol CanBark {
func bark() -> String
}
class Animal {
func animalType() -> String {
return "Animal"
}
}
@dustinsmith1024
dustinsmith1024 / gist:1538180
Created December 30, 2011 06:03
Radio Inputs in Django that don't have LABEL wraps
"""
1. Inherit from the normal RadioInput and copy the RadioInput __unicode__ method. Then change it up how you please:
"""
class RadioInputNoWrap(RadioInput):
def __unicode__(self):
if 'id' in self.attrs:
label_for = ' for="%s_%s"' % (self.attrs['id'], self.index)
else:
label_for = ''
choice_label = conditional_escape(force_unicode(self.choice_label))
@siddhi
siddhi / pyconindia_dsl.py
Created September 16, 2011 06:33
Domain Specific Languages in Python - Pycon India - 17 Sep 2011
from pyparsing import *
# By default, PyParsing treats \n as whitespace and ignores it
# In our grammer, \n is significant, so tell PyParsing not to ignore it
ParserElement.setDefaultWhitespaceChars(" \t")
def parse(input_string):
def convert_prop_to_dict(tokens):
"""Convert a list of field property tokens to a dict"""
prop_dict = {}