This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = app || {}; | |
$(function(){ | |
var app.Signature = Backbone.Model.extend({ | |
initialize: function(){ | |
return $.ajax({ | |
url: '/auth/' | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"`' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |