Skip to content

Instantly share code, notes, and snippets.

View sampsyo's full-sized avatar

Adrian Sampson sampsyo

View GitHub Profile
@sampsyo
sampsyo / multijson.py
Created April 14, 2011 18:59
quick & dirty reading/writing of files containing multiple JSON objects
"""A couple of very simple utilities for reading and writing files
that contain multiple JSON values. Could be useful in situations where
you're generating a bunch of data for later processing and then, later,
you want to read it in an element at a time.
The json module doesn't really support streaming reads, though, so this
is limited by that. If you need real streaming, you probably want to use
something like ijson:
http://pypi.python.org/pypi/ijson/
"""
@sampsyo
sampsyo / clopper_pearson.py
Last active October 31, 2018 16:21
the Clopper-Pearson method for getting a confidence interval for an estimated a Bernoulli parameter
import scipy.stats
import math
import random
def clopper_pearson(x, n, alpha=0.05):
"""Estimate the confidence interval for a sampled Bernoulli random
variable.
`x` is the number of successes and `n` is the number trials (x <=
@sampsyo
sampsyo / index.js
Created March 5, 2018 13:58
a Metalsmith config
var Metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
var layouts = require('metalsmith-layouts');
var sass = require('metalsmith-sass');
var metadata = require('metalsmith-metadata');
var inplace = require('metalsmith-in-place');
var ignore = require('metalsmith-ignore');
var metadataPat = require('./metalsmith-metadata-pattern');
var marked = require('marked');
@sampsyo
sampsyo / fixedpoint.js
Created February 16, 2017 02:49
a fixed-point combinator in JavaScript
// Z = \t. (\f. t (\z. f f z)) (\f. t (\z. f f z))
function Z(t) {
return ( (f) => t((z) => (f(f))(z)) ) ( (f) => t((z) => (f(f))(z)) );
}
function fact_template(f) {
return function(n) {
if (n <= 1) {
return 1;
} else {
@sampsyo
sampsyo / bars-with-average.json
Created February 15, 2017 19:41
Dominik's example with a reference line at the average
{
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A","b": 28},
{"a": "B","b": 55},
{"a": "C","b": 43},
{"a": "D","b": 91},
{"a": "E","b": 81},
{"a": "F","b": 53},
@sampsyo
sampsyo / feat.ml
Last active October 27, 2016 15:16
GADTs for features
(* General features. This starts out as an "empty" type, which we'll then
extend. We also define feature values and feature vectors. *)
type 'a feat = ..
type 'a value = 'a feat * float
type 'a fvec = 'a value list
(* Domain adaptation. *)
import sys
import os
PY2 = sys.version_info[0] == 2
def py3_path(path):
"""Convert a bytestring path to Unicode on Python 3 only. On Python
2, return the bytestring path unchanged.
@sampsyo
sampsyo / rn.py
Created February 21, 2014 18:52
import re
import sys
import os
for path in sys.argv[1:]:
with open(path) as f:
contents = f.read()
m = re.search(r'created_at: (.*)', contents)
d, m, y = map(int, m.group(1).split('/'))
[
{
"union": [
{
"object": {
"tag": {
"literal": "schedule"
},
"attendees": {
"array": {

The GPU languages are all corrupted C variants where all safety is sacrificed in the name of low-level control. And the awkward dance for CPU–GPU communication is "stringly typed."

Verilog/VHDL are leaky abstractions with creaky tools; they're just very old languages with zero of the modern conveniences. Bluespec seems rad and I don't know why it's not more popular! Same with Chisel: https://chisel.eecs.berkeley.edu/