Skip to content

Instantly share code, notes, and snippets.

View eculver's full-sized avatar
🧠
Braining

Evan Culver eculver

🧠
Braining
View GitHub Profile
@eculver
eculver / MySQL select word count
Created February 22, 2010 20:02
MySQL select word count
SELECT SUM(LENGTH(name) - LENGTH(REPLACE(name, ' ', ''))+1) FROM table
@eculver
eculver / CSS Reset
Created March 8, 2010 19:52
CSS Reset
/* http://meyerweb.com/eric/tools/css/reset/ */
/* v1.0 | 20080212 */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
@eculver
eculver / .bashrc
Created March 23, 2010 23:43
.bash_profile / .bashrc
IP_ADDR=`ifconfig | awk '/192/ { print $2 }'`
alias l='ls -l'
alias ll='ls -la'
alias runserver='python manage.py runserver $IP_ADDR:8000'
alias runserver80='sudo python manage.py runserver 127.0.0.1:80'
alias syncdb='python manage.py syncdb'
alias synergys='~/bin/synergy/synergys -f -c ~/bin/synergy/synergy.conf'
alias fink='/sw/bin/fink'
alias rabbitmq-server='sudo /opt/local/lib/erlang/lib/rabbitmq_server-1.6.0/sbin/rabbitmq-server'
@eculver
eculver / Simple Django cache backend overrides for dealing with python-memcached differences between cmemcache.
Created March 30, 2010 22:38
Simple Django cache backend overrides for dealing with python-memcached differences between cmemcache.
from django.core.cache.backends import memcached
from django.utils.encoding import smart_str
"""
Simple Django cache backend overrides for dealing with python-memcached
differences between cmemcache.
For Django 1.2. All methods except `set_many` and `delete_many` will work for Django 1.1
Use by pointing to it in settings, for example:
@eculver
eculver / IE PNG Fix
Created March 31, 2010 00:20
IE PNG Fix
<!--[if lte IE 6]>
<style type="text/css">
img, div, input, a { behavior: url("http://example.com/path/to/iepngfix.htc") }
</style>
<![endif]-->
@eculver
eculver / filter microsoft word special characters
Created April 18, 2010 04:30
convert microsoft word special characters to html entities
import re
def convert_1252_codes(text):
"""Convert windows-1252 characters to appropriate html entities.
@param str String to filter
@type string/unicode
@return unicode version of filtered string
Adapted from: http://effbot.org/zone/unicode-gremlins.htm
@eculver
eculver / mples of how to implement inheritance with Django models
Created April 18, 2010 05:36
Examples of how to implement inheritance with Django models
"""Examples of how to implement inheritance with Django models.
Idea here is DRY (don't repeat yourself). If models are similar, let them
share functionality to the extent that its ancestrty makes sense.
It's important to note is that because of the "abstract = True", Django knows
not to create tables for those models, and instead only creates tables for
those models that implement those abstract base classes.
It can also be noted that instead of having one gigantic, monolithic models.py
@eculver
eculver / A generic cache manager.
Created April 20, 2010 17:55
A generic cache manager
import random
from django.db import models
from django.core.cache import cache
class CacheManager(models.Manager):
'''Generic Cache Manager based on the concept of generator ids to
handle invalidation of collections.
'''
def _test_model(self, obj):
@eculver
eculver / css color + text shadow
Created April 28, 2010 19:58
css color + text shadow
/* http://www.newthink.net */
color: #2a2a2a;
text-shadow: rgba(0, 0, 0, 0.113281) 2px 2px 0px;
/* http://ozmm.org */
color: red;
text-shadow: #0c0c0c 2px 2px 1px;
/* http://peroty.tumblr.com */
color: #f2e3c6;
@eculver
eculver / random color
Created June 4, 2010 18:25
random color
'#' + (~~(Math.random() * 16777215)).toString(16);