Skip to content

Instantly share code, notes, and snippets.

View mhulse's full-sized avatar
👋
👁 ❤️ open source software …

Michael Hulse mhulse

👋
👁 ❤️ open source software …
  • Instructure Inc.
  • Eugene, Oregon
View GitHub Profile
@mhulse
mhulse / models.py
Created May 23, 2011 16:43
Abstract class for generic fields; in this case "created" and "modified".
# ...
class Base(models.Model):
created = models.DateTimeField(_(u'Created'), editable=False)
modified = models.DateTimeField(_(u'Modified'), editable=False)
class Meta:
abstract = True
@mhulse
mhulse / validators.py
Created June 13, 2011 18:04
Year validator for a Django (1.2+) IntegerField.
from django.core.exceptions import ValidationError
import time
import re
def validate_year(value):
"""
Validator function for model.IntegerField()
* Validates a valid four-digit year.
* Must be a current or future year.
@mhulse
mhulse / helpers.py
Created June 15, 2011 19:34
Django (1.3) Google Maps v3 Geocoder service lookup example
import urllib, urllib2, simplejson
from django.utils.encoding import smart_str
def get_lat_lng(location):
# http://djangosnippets.org/snippets/293/
# http://code.google.com/p/gmaps-samples/source/browse/trunk/geocoder/python/SimpleParser.py?r=2476
# http://stackoverflow.com/questions/2846321/best-and-simple-way-to-handle-json-in-django
# http://djangosnippets.org/snippets/2399/
@mhulse
mhulse / models.py
Created June 17, 2011 17:42
Django basic/simple category/sub-category model.
# ...
class Category(Base):
slug = models.SlugField(_(u'slug'), max_length=100, unique=True)
title = models.CharField(_(u'title'), max_length=250)
parent = models.ForeignKey('self', blank=True, null=True, related_name='child')
class Meta:
verbose_name_plural = 'Categories'
@mhulse
mhulse / models.py
Created June 23, 2011 21:38
Basic/simple example of abstract base models and multiple inheritence...
# ...
######################################
##
## Abstract models:
##
######################################
class Base(models.Model):
@mhulse
mhulse / text-overflow.css
Created July 6, 2011 16:37
Text overflow CSS example...
/*
**
** CSS: text-overflow
** URI: http://www.quirksmode.org/css/textoverflow.html
**
** JS: jquery.textOverflow
** Website: http://www.bramstein.com/projects/text-overflow/
** About: This jQuery plugin implements a simplified version of the CSS3 text-overflow property [for Firefox].
** Compatibility:
** Mac: Firefox v3.6, Safari v4.0.3 (5531.9), Opera v10.10, Chrome v4.0.249.49 (35163) beta
@mhulse
mhulse / test.css
Created July 7, 2011 20:00
CSS gradient test using % and px as units...
.test {
background: #000;
background: -moz-linear-gradient(top, #000 0, #000 2px, #5f5f5f 2px, #5f5f5f 3px, #1a1a1a 3px, #1a1a1a 4px, #333 4px, #333 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #000), color-stop(2%, #000), color-stop(2%, #5f5f5f), color-stop(3%, #5f5f5f), color-stop(3%, #1a1a1a), color-stop(4%, #1a1a1a), color-stop(4%, #333), color-stop(100%, #333));
background: -webkit-linear-gradient(top, #000 0, #000 2px, #5f5f5f 2px, #5f5f5f 3px, #1a1a1a 3px, #1a1a1a 4px, #333 4px, #333 100%);
background: -o-linear-gradient(top, #000 0, #000 2px, #5f5f5f 2px, #5f5f5f 3px, #1a1a1a 3px, #1a1a1a 4px, #333 4px, #333 100%);
background: -ms-linear-gradient(top, #000 0, #000 2px, #5f5f5f 2px, #5f5f5f 3px, #1a1a1a 3px, #1a1a1a 4px, #333 4px, #333 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#333333', GradientType=0);
background: linear-gradient(top, #000 0, #000 2px, #5f5f5f 2px, #5f5f5f 3px, #1a1a1a 3px, #1a1a1a 4px,
@mhulse
mhulse / ajax_helper.php
Created July 15, 2011 18:35
PHP test for an ajax request.
<?php
function is_ajax() {
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') ? TRUE : FALSE;
}
@mhulse
mhulse / links.css
Created July 27, 2011 22:53
CSS a:link examples...
@mhulse
mhulse / inc.csp
Created July 28, 2011 23:32
CSP includes and query string variables...
<csp:include page="/csp/cms/sites/web/demos/test1.inc.csp?var=foo">
#($get(%request.Data("var", 1)))#
......
Output is:
foo foo