Skip to content

Instantly share code, notes, and snippets.

View aezell's full-sized avatar
😶

Alex Ezell aezell

😶
View GitHub Profile
@aezell
aezell / backbone_app.js
Created October 14, 2012 01:27
Backbone Attempt
var app = app || {};
$(function(){
var app.Signature = Backbone.Model.extend({
initialize: function(){
return $.ajax({
url: '/auth/'
});
}
});
@aezell
aezell / verbatim.py
Created October 14, 2012 00:32
verbatim Django template tag
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@aezell
aezell / sa_middleware.py
Created September 14, 2012 18:46
SA Middleware
class SqlAlchemyMiddleware:
"""
A simple SA middleware class that creates a global scoped session from the
DATABASE_URL parameter in the settings file.
"""
def process_view(self, request, view_func, view_args, view_kwargs):
from django.conf import settings
from django.http import HttpResponseRedirect
try:
@aezell
aezell / nonce.py
Created September 13, 2012 13:29
nonce creation
# PHP code
function create_nonce()
{
$mt = microtime();
$rand = mt_rand();
return preg_replace('/[^a-zA-Z0-9]/', '', base64_encode(sha1($mt . $rand, true)));
}
# Python code
@aezell
aezell / test_twilio.py
Created August 29, 2012 19:58
Mock Twilio
@patch('twilio.rest.resources.SmsMessages')
def test_send_sms_valid_args(self, MockClass):
instance = MockClass.return_value
instance.create.return_value = None
to_number = 5555555555
msg = 'Hello world'
send_sms(to_number, msg)
instance.create.assert_called_once_with(to='+1' + str(to_number),
body=msg, from_=settings.TWILIO_FROM_NUM)
@aezell
aezell / shakes.py
Created August 27, 2012 21:20
Sunset and Altitude for Shakespeare's Plays
# Caveat, the dates included are Julian but PyEphem and Python only really know about Gregorian.
# Additionally, not all of these performances were at The Globe so we should be moving the Observer
# accordingly. It still largely proves the hypothesis.
import argparse
from datetime import datetime
import ephem
from prettytable import PrettyTable
@aezell
aezell / sunset.txt
Created August 26, 2012 16:00
Shakespeare Plays and Sunset
python shakes.py -t 15:00:00 -a
Total Performances: 18
Candle Performances 16
Twilight Candle Performances 14
+--------------------------+-----------------------+-----------------------+-----------------------+-----------+-----------------------+--------------------+------------------+
| Play | Curtain Up | Sunset | Time Difference | Candles | Twilight Date | Twilight Candles | Sun's Altitude |
+--------------------------+-----------------------+-----------------------+-----------------------+-----------+-----------------------+--------------------+------------------+
| Henry VI, Part I | 1592/3/3 15:00:00 | 1592/3/3 17:50:08 | 2 hours, 50 minutes | Y | 1592/3/3 18:19:24 | N | 21:49:26.4 |
| Titus Andronicus | 1594/1/23 15:00:00 | 1594/1/23 16:40:13 | 1 hours, 40 minutes | Y | 1594/1/23 17:12:49 | Y | 10:20:11.3 |
| Taming of the Shrew |
@aezell
aezell / gitconfig.sh
Created June 26, 2012 14:52
Pruning Branches
[alias]
prunelocal = !sh -c 'git branch -d `git branch --merged | grep -v "^*"`'
pruneorigin = !sh -c 'git push origin `git branch -r --merged | grep \"^ origin/\" | grep -v "/master$" | sed "s/origin./:/g" | tr -d "\\n"`'
@aezell
aezell / datetime_safe.py
Created June 21, 2011 21:55
Django datetime
# Python's datetime strftime doesn't handle dates before 1900.
# These classes override date and datetime to support the formatting of a date
# through its full "proleptic Gregorian" date range.
#
# Based on code submitted to comp.lang.python by Andrew Dalke
#
# >>> datetime_safe.date(1850, 8, 2).strftime("%Y/%M/%d was a %A")
# '1850/08/02 was a Friday'
from datetime import date as real_date, datetime as real_datetime
def render_data(self, obj):
if isinstance(obj,dict):
value = obj.get(self.id, None)
if not value and 'fields' in obj: # added
value = obj['fields'].get(self.id, None) # added
else:
value = getattr(obj,self.id, None)
if callable(value):
return self.format_data(value())