Skip to content

Instantly share code, notes, and snippets.

View hanksims's full-sized avatar

Hank Sims hanksims

View GitHub Profile
@hanksims
hanksims / prisms.py
Last active December 15, 2019 18:50
Prisms
In [112]: def find_prisms():
...: found = set()
...: for a in range(1,10000):
...: for b in range(1,10000):
...: numerator = 2*a*b
...: denominator = a*b - 2*a - 2*b
...: if denominator > 0:
...: c = numerator/denominator
...: if c.is_integer():
...: found.add(tuple(sorted((a,b,int(c)))))
import mechanize
import cookielib
from BeautifulSoup import BeautifulSoup
URL = 'http://leginfo.legislature.ca.gov/faces/codes.xhtml'
class Browser(object):
def __init__(self, section, code):
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
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()
@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)
In [62]: run ncjulator
NUMBER OF VOTES = 308
===============
9.1 ---> 28
34.4 ---> 106
3.2 ---> 10
6.8 ---> 21
from __future__ import division
from decimal import Decimal
import time
TARGETS = set([
float(34.4),
float(9.1),
float(6.8),
float(3.2),
])
@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
@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()
"""
A standalone Python script to utterly refute some wide-circulation bullshit that is currently softening many minds.
"""
import datetime
i = 1900
j = 2100
valid = []
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) {