Skip to content

Instantly share code, notes, and snippets.

@whitews
whitews / config.txt
Created April 9, 2020 18:11
parse config
# MRN, ACCN, and Study Date
# sl:mrn,accn,stdt
# MRN, ACCN
sl:mrn,accn
# MRN, Report Date
# sl:mrn,rptdt
@whitews
whitews / index.html
Created February 26, 2016 21:59
Pulsing circles on click in D3.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
svg {
background-color: #444455;
}
@whitews
whitews / worker_multiproc.py
Created June 4, 2015 20:03
Python multiprocessing example
import random
import multiprocessing
import time
import logging
logging.basicConfig(
level=logging.DEBUG,
format='(%(processName)-10s) %(message)s',
)
@whitews
whitews / worker_thread.py
Created June 4, 2015 19:36
Python threading example
import random
import threading
import time
import logging
logging.basicConfig(
level=logging.DEBUG,
format='(%(threadName)-10s) %(message)s',
)
@whitews
whitews / example_usage.py
Last active August 29, 2015 14:00
Find modes using Expectation-Maximization of a Gaussian Mixture Model
import numpy as np
import matplotlib.pyplot as plt
from utils import get_gmm_modes
data = np.array([3643, 4699, 91, 144, 13, 3662, 3870, 4360, 90,
62, 8100, -48, 3679, 4479, 115, 4105, 69, -22,
-55, 4339, 87, -24, 4273, 142, 4956, 4256, 4162,
134, 4090, 86, 4100, 4366, 150, 4600, -63, 4346,
136, 4531, 3966, 4394, 67, 58, -48, 3793, 4239,
4239, 88, 4514, 99, 4399, 4212, 144, 12, 3768,
@whitews
whitews / AWS_S3_PrivateBucket_GET
Last active December 19, 2015 06:49
AWS S3 access to a private bucket - the AWS access ID user needs ListBucket privileges
import base64
import datetime, time
import sha, hmac
import email.utils
import requests
bucket_name = 'kick'
aws_access_id = "ABCDEFGHIJKLMNOPQ123"
aws_secret_access_key = "some-secret-amazon-aws-secret-access-key"
url = 'http://' + bucket_name + '.s3.amazonaws.com/'
@whitews
whitews / README.md
Last active December 16, 2015 07:09
US Government Spending

A plot of US government spending over time with an animate pie chart showing the annual percentage breakdown by spending category.

@whitews
whitews / recursive_find_children.py
Created April 4, 2013 13:29
Recursively find children in a dictionary and return them all as a flat list
def find_children(d, i):
l = list()
l.append(d['name'])
d['id'] = i
if 'children' in d:
for child in d['children']:
l.extend(find_children(child, i + len(l)))
return l
@whitews
whitews / numpy_vs_unpack.py
Last active December 14, 2015 19:19
Example showing the speed up of using numpy to parse well-structured binary data
# on Unix make a 10MB bin file using:
# dd if=/dev/random of=10meg.bin bs=1024 count=$[1024*10]
from timeit import timeit
count = 50
setup = '''
import os
import numpy as np
from struct import calcsize, unpack
@whitews
whitews / post_stuff.py
Created March 10, 2013 21:55
Example script to send an HTTPS POST via httplib
import sys
import httplib
from httplib import HTTPException
import json
DEBUG = False
BOUNDARY = '--------Boundary'
def post_stuff(host, post_url, field_dict):