Skip to content

Instantly share code, notes, and snippets.

View jspeis's full-sized avatar

Jonathan Speiser jspeis

View GitHub Profile
@jspeis
jspeis / midp.js
Created February 23, 2018 13:48
Computing Mid-P Exact Confidence Interval
// Credit to @JogoShugh
// Sourced from https://github.com/JogoShugh/OpenEpi.com/blob/8c90dc075c6a9b8e2a8de8ff26d7cd0b1987762a/OpenEpi/Proportion/Proportion.js
function criticalValue(confLevel) {
// Returns z value for various levels of confidence and 1 degree
// of freedom. OEConfLevel must be expressed as
// a string with two digits, then two optional digits, without a % sign.
const critMap = {
.99999: 15.137,
.99: 6.635,
@jspeis
jspeis / datausa.py
Created June 23, 2016 02:46
Easily import DataUSA API into pandas dataframe
import pandas as pd
import requests
def datafold(data):
return [dict(zip(data["headers"], d)) for d in data["data"]]
def api_to_df(url):
req = requests.get(url)
data = datafold(req.json())
df = pd.DataFrame(data)
@jspeis
jspeis / basic.html
Created February 3, 2016 15:48
proof of concept for saving map tiles from SVG to PNG
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
margin: 0;
}
path {
fill: none;
@jspeis
jspeis / test.html
Last active February 2, 2016 15:33
Example d3plus viz to PNG
<!doctype html>
<meta charset="utf-8">
<!-- load D3js -->
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="http://gabelerner.github.io/canvg/rgbcolor.js"></script>
<script type="text/javascript" src="http://gabelerner.github.io/canvg/StackBlur.js"></script>
<script type="text/javascript" src="http://gabelerner.github.io/canvg/canvg.js"></script>
@jspeis
jspeis / .vimrc
Created June 24, 2015 16:36
My old vimrc file
" Jonathan Speiser's vimrc file
" Based on Yosef Berman's vimrc file
:syntax on
:set number
:set nohlsearch
" indentation stuff
:set autoindent
:set expandtab
:set tabstop=4
@jspeis
jspeis / gist:beb959dd19bf76c34d69
Last active August 29, 2015 14:17
RAIS growth test
SELECT * from rais_yb y1, rais_yb y2
WHERE y1.year + 1 = y2.year
AND y1.bra_id = y2.bra_id
AND y1.wage IS NOT NULL
AND y2.wage_growth IS NULL
AND y2.wage IS NOT NULL
AND (y1.wage != 0 OR (y1.wage = 0 AND y2.wage!=0))
LIMIT 1
SELECT * from rais_ybi y1, rais_ybi y2
@jspeis
jspeis / setup.py
Created September 16, 2014 17:21
Patched version of PyTables setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Setup script for the tables package"""
import os
import re
import sys
import ctypes
import tempfile
@jspeis
jspeis / gist:1586821
Created January 10, 2012 03:55
convert arabic numeral to roman numerals
sub to_roman_numeral {
my %roman = (
1_000_000 => '(MBAR)',
900_000 => '(CBAR)(MBAR)',
500_000 => '(DBAR)',
400_000 => '(CBAR)(DBAR)',
100_000 => '(CBAR)',
90_000 => '(XBAR)(CBAR)',
50_000 => '(LBAR)',
40_000 => '(XBAR)(LBAR)',
class A():
test = 'Everyone'
def __init__(self):
self.local = 'Just Me'
def __str__(self):
return self.test + " " + self.local
x = A()
import random
class A(object):
def __init__(self):
self.x = random.randint(0,100000)
def f(self):
return A()
def __str__(self):
return str(self.x)
a = A()