Skip to content

Instantly share code, notes, and snippets.

View gabegaster's full-sized avatar

Gabriel Gaster gabegaster

View GitHub Profile
@gabegaster
gabegaster / gist:904e34a68f4e1893b0e0
Created May 5, 2015 20:25
Mr S and Mr P: From http://programmingpraxis.com/2009/10/23/mr-s-and-mr-p/ and told to me by Mike Stringer. My answer in pure python.
"""From http://programmingpraxis.com/2009/10/23/mr-s-and-mr-p/ and
told to me by Mike Stringer. John McCarthy, who discovered Lisp,
attributes this puzzle to Hans Freudenthal:
We pick two numbers a and b, so that 100>a,b>1. We tell
Mr. P. the product ab and Mr. S. the sum a+b. Then Mr. S. and
Mr. P. engage in the following dialog:
Mr. P.: I don't know the numbers.
Mr. S.: I knew you didn't know. I don't know either.
@gabegaster
gabegaster / isotropic.py
Last active August 29, 2015 14:05
Finding nested isotropic spaces in characteristic 2.
from itertools import combinations, product
import numpy as np
import csv
def get_lucas_matrix(genus=3):
# generate V, all non-zero binary 2*genus tuples.
V = (np.array(m)
for m in product(*( [range(2)]*genus*2 ))
if np.array(m).sum()>0)
sample_a.dat
sample_b.dat
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js"></script>
</head>
<body>
<div id="chart">
</div>
<script type="text/javascript">
var w = 960,
@gabegaster
gabegaster / tempodb_twine_daemon_example.py
Created January 28, 2014 20:44
scrape twine data and push to tempodb
import requests
import json
import datetime
import time
import pytz
import tempodb
# Modify these with your credentials found at: http://tempo-db.com/manage/
API_KEY = 'intentionally left blank'
API_SECRET = 'fffffffffffffffffffff'
'''
An example daemon to query twine and log results.
Gabe Gaster, Datascope Analytics, 2014
gabe@datascopeanalytics.com
'''
import requests, json, time
twine_id = "00000----------" # twine id
@gabegaster
gabegaster / know_the_cubes.py
Created January 24, 2014 16:35
Train Yourself to Take Cube Roots
'''
A script to train myself on knowing the cuberoots of perfect cubes with 6 digits or less.
'''
import sys, random, time
print "welcome to know these ten cubes "
count = 0
start = time.time()
@gabegaster
gabegaster / holomorphic.jl
Last active December 20, 2015 21:28 — forked from johnmyleswhite/holomorphic.jl
named functions (du_dx, du_dy, dv_dx, dv_dy) to make it completely transparent that the cauchy-riemann equations are being used, and what the actual check is.
# f(z = x + iy) = u(x, y) + i * v(x, y)
function finite_difference{T <: Complex}(f::Function,
z::T,
alongx::Bool = true,
alongu::Bool = true)
epsilon = sqrt(eps(max(abs(one(T)), abs(z))))
if alongx
zplusdz = z + epsilon
else
zplusdz = z + epsilon * im
@gabegaster
gabegaster / BabyBib.r
Created April 23, 2012 16:53
Use plyr to get figure out which baby names are biblical
library(plyr)
library(reshape2)
library(ggplot2)
bnames <- read.csv("bnames.csv", stringsAsFactors = FALSE)
bibnames <- read.csv('BiblicalNames.txt')$BiblicalNames
bnames$bibl <- is.element(bnames$name, bibnames)
bibpop <- ddply(bnames, c('year', 'sex', 'bibl'), summarise, tot=sum(percent))
bibpopT <- subset(bibpop, bibl==TRUE)
qplot(year, tot, data=bpopT, geom='line', colour=sex, ymin=0, ymax=1)