Skip to content

Instantly share code, notes, and snippets.

View swilcox's full-sized avatar

Steven Wilcox swilcox

View GitHub Profile
@swilcox
swilcox / clarion_utils.py
Created September 19, 2011 18:36
python code to convert a standard date to a clarion date
import datetime
CLARION_DAY_ZERO = datetime.date(1800,12,28) #this is the important date to work with!
def date_to_clarion_date(input_date):
"""
this is evil because I'm not checking jack...
@swilcox
swilcox / horn.py
Created October 10, 2011 20:05
horn
if brakes.abs_engaged:
horn.volume += 500
import redis
from django.conf import settings
from django.core.signals import request_finished
try:
from eventlet.corolocal import local
except ImportError:
from threading import local
@swilcox
swilcox / crappy_page_filters.py
Created July 26, 2012 21:57
a really crap set of template filters for django pagination rather than subclassing and mod'ing it
"""
Usage info:
Slap this file in a templatetags subdirectory off one of your apps:
In a template:
{% load crappy_page_filters %}
Then... given a situation like you were dealing with Haystack (and Twitter Boostrap style CSS)
@swilcox
swilcox / _mgraph.md
Last active October 6, 2017 21:08
Multi-graph example widget for Shopify's Dashing dashboard

Multi-graph widget for Dashing

Description

Multi-graph widget for Shopify's dashing to display a comparison style graph (or stacked with a minor modification). Obviously, this is an example that is built heavily on the existing graph widget that is provided with dashing. This widget provides a more clear framework for expanding the graph for multiple series (or nodes) of data. After seeing the example code, it should be fairly easy to expand to 3 or more overlaid graphs (although colors might get tricky). And really, this is just a slightly greater use of the cool rickshaw graphs.

To use this widget:

@swilcox
swilcox / distcompute.py
Last active August 29, 2015 14:08
distance between 2 coordinates
import math
def distance(origin, destination):
#assumes origin and destination are (lat, long) pairs where lat and long are decimals
lat1, lon1 = origin
lat2, lon2 = destination
#radius = 6371 # km <-- use this if metric
radius = 3961 # miles <-- use this if english / miles
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1)
@swilcox
swilcox / sphinx.rb
Last active January 15, 2016 02:47 — forked from alexstubbs/sphinx.rb
Brew formula for install sphinx 0.9.8.1 based on homebrew formula sphinx 2.0.4 git checkout 8dbb32e /usr/local/Library/Formula/sphinx.rb
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end
@swilcox
swilcox / redis_helper.py
Created May 2, 2017 13:26
Getting a connection to redis
import redis
import mockredis
from django.conf import settings
from django.core.signals import request_finished
try:
from eventlet.corolocal import local
except ImportError:
from threading import local
@swilcox
swilcox / logging.py
Created May 26, 2022 16:37
JSON logger
"""
Shamelessly lifted from https://github.com/sebest/json-logging-py in order
to simplify customization.
"""
import os
from datetime import datetime
import json
import logging
import socket