Skip to content

Instantly share code, notes, and snippets.

View hanksims's full-sized avatar

Hank Sims hanksims

View GitHub Profile
@hanksims
hanksims / gist:334240
Created March 16, 2010 17:15
django-slimmer w/SSI allowance
--- a/slimmer.py 2010-03-16 16:58:11.000000000 +0000
+++ b/slimmer.py 2010-03-16 17:06:17.000000000 +0000
@@ -90,10 +90,14 @@
f_MD = re.MULTILINE|re.DOTALL
f_M = re.MULTILINE
-# This expression matches normal comments but specifically ignores Internet
-# Explorer downlevel-hidden conditional comments - see MSDN for syntax details:
-# http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx#syntax
-html_comments_oneline = re.compile(r'<!--[^[][^\r\n]+-->')
var redis = require("redis"),
client1 = redis.createClient(),
client2 = redis.createClient(),
client3 = redis.createClient(),
client4 = redis.createClient(),
msg_count = 0;
redis.debug_mode = false;
client1.on("psubscribe", function (pattern, count) {
var redis = require("redis"),
client1 = redis.createClient(),
client2 = redis.createClient(),
client3 = redis.createClient(),
client4 = redis.createClient(),
msg_count = 0;
redis.debug_mode = false;
client1.on("psubscribe", function (pattern, count) {
"""
A standalone Python script to utterly refute some wide-circulation bullshit that is currently softening many minds.
"""
import datetime
i = 1900
j = 2100
valid = []
@hanksims
hanksims / gist:1595055
Created January 11, 2012 14:59
Monitoring the initial values of Django objects
class Foo(models.Model):
bar = models.CharField(max_length=50)
def __init__(self, *args, **kwargs):
self.bar_initial = self.bar
super(Foo, self).__init__(*args, **kwargs)
def save(self, *args, **kwargs):
if self.bar == self.bar_initial:
do_stuff()
@hanksims
hanksims / a README.py
Created January 15, 2012 22:53
Port Distance Calculator
# Great circle distance calculations between selected Asian ports and selected ports on the West Coast of
# the Americas.
#
# Using GeoDjango ORM to interact with PostGIS geography columns.
#
# https://docs.djangoproject.com/en/dev/ref/contrib/gis/
# http://postgis.refractions.net/docs/ch04.html#PostGIS_Geography
from __future__ import division
from decimal import Decimal
import time
TARGETS = set([
float(34.4),
float(9.1),
float(6.8),
float(3.2),
])
In [62]: run ncjulator
NUMBER OF VOTES = 308
===============
9.1 ---> 28
34.4 ---> 106
3.2 ---> 10
6.8 ---> 21
@hanksims
hanksims / pick_a_winner.py
Created July 11, 2014 21:09
The LoCO Facebook Like Contest Winner Picker!
import facebook
import webbrowser
import time
import sys
import os
FACEBOOK_TOKEN = '<YOUR-FACEBOOK-TOKEN>'
OBJECT_ID = '<YOUR-OBJECT-ID>'
api = facebook.GraphAPI(FACEBOOK_TOKEN)
import ephem
def human_moon(observer):
target_date_utc = observer.date
target_date_local = ephem.localtime( target_date_utc ).date()
next_full = ephem.localtime( ephem.next_full_moon(target_date_utc) ).date()
next_new = ephem.localtime( ephem.next_new_moon(target_date_utc) ).date()
next_last_quarter = ephem.localtime( ephem.next_last_quarter_moon(target_date_utc) ).date()
next_first_quarter = ephem.localtime( ephem.next_first_quarter_moon(target_date_utc) ).date()
previous_full = ephem.localtime( ephem.previous_full_moon(target_date_utc) ).date()