Skip to content

Instantly share code, notes, and snippets.

View doismellburning's full-sized avatar
🔥

Kristian Glass doismellburning

🔥
View GitHub Profile
@doismellburning
doismellburning / gist:1869463
Created February 20, 2012 14:25
Django 1.3.1 EmailValidator
email_re = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE) # domain
validate_email = EmailValidator(email_re, _(u'Enter a valid e-mail address.'), 'invalid')
@doismellburning
doismellburning / gist:1877208
Created February 21, 2012 16:13
Determine age from a date of birth
from datetime import date
def determine_age(dob):
"""
Surprisingly nontrivial - I don't claim this function to be very correct...
"""
today = date.today()
age = today.year - dob.year
if today.month < dob.month:
age -= 1
@doismellburning
doismellburning / __init__.py
Created February 27, 2012 17:21
Django settings for multiple environments
import os
from base import *
deployment = os.getenv("DJANGO_DEPLOYMENT")
#TODO There's probably a nicer way of doing this
if deployment == "live":
from live import *
elif deployment == "staging":
from staging import *
@doismellburning
doismellburning / gist:2028973
Created March 13, 2012 14:06
Heroku and Unicode

I appear to be unable to work out how to send Unicode characters via Heroku

Heroku

$ heroku run python
Running python attached to terminal... up, run.1
Python 2.7.2 (default, Oct 31 2011, 16:22:04) 
[GCC 4.4.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.

@doismellburning
doismellburning / live.py
Created March 26, 2012 18:30
Django settings for S3
AWS_STORAGE_BUCKET_NAME = PROJECT_NAME
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL
@doismellburning
doismellburning / locals_hackery.py
Created April 23, 2012 00:15
Grimness with locals
import os
_locals = locals()
def f(x):
_locals[x] = os.getenv(x)
f('DJANGO_DEBUG')
print DJANGO_DEBUG
@doismellburning
doismellburning / settings.py
Created May 25, 2012 01:23
Django settings for SendGrid
EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
if os.getenv('SENDGRID_USERNAME') is not None:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = os.getenv('SENDGRID_USERNAME')
EMAIL_HOST_PASSWORD = os.getenv('SENDGRID_PASSWORD')
EMAIL_PORT = 587
EMAIL_USE_TLS = True
@doismellburning
doismellburning / settings.py
Created June 9, 2012 12:43
Template config in Django
PROJECT_DIR = os.path.dirname(__file__)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
@doismellburning
doismellburning / wtf.rb
Created July 25, 2012 10:53
Genuine dubyateeyeff
#!ruby
# Courtesy of @jcoglan - http://twitter.com/#!/jcoglan/status/228075420694753280
def foo(a, b=0, c=0, d)
a + d
end
print foo(2,3,4)
# 6...
import hudson.model.*
import hudson.maven.*
import hudson.tasks.*
import com.tikal.hudson.plugins.notification.HudsonNotificationProperty
import com.tikal.hudson.plugins.notification.Endpoint
import com.tikal.hudson.plugins.notification.Protocol
String URL = "http://example.com/bot/jenkins"
for(item in Hudson.instance.items) {