Skip to content

Instantly share code, notes, and snippets.

Adrian Sampson sampsyo

Block or report user

Report or block sampsyo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sampsyo
sampsyo / index.js
Created Mar 5, 2018
a Metalsmith config
View index.js
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 Feb 16, 2017
a fixed-point combinator in JavaScript
View fixedpoint.js
// 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 Feb 15, 2017
Dominik's example with a reference line at the average
View bars-with-average.json
{
"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 Oct 27, 2016
GADTs for features
View feat.ml
(* 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. *)
View py3_path.py
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.
View fisr.py
"""This is a Python transcription of the famous Quake III "fast inverse
square root" function. Run the script to see a quick comparison with an
"exact" square root.
"""
import struct
import math
# From:
View schema.json
[
{
"union": [
{
"object": {
"tag": {
"literal": "schedule"
},
"attendees": {
"array": {
View DSLs.md

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/

View 1942.diff
diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py
index 88c72cd..f570504 100644
--- a/beetsplug/fetchart.py
+++ b/beetsplug/fetchart.py
@@ -648,14 +648,15 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin):
'coverart', 'itunes', 'amazon', 'albumart'],
'google_key': None,
'google_engine': u'001442825323518660753:hrh5ch1gjzm',
- 'fanarttv_key': None
+ 'fanarttv_key': None,
@sampsyo
sampsyo / clopper_pearson.py
Last active Oct 31, 2018
the Clopper-Pearson method for getting a confidence interval for an estimated a Bernoulli parameter
View clopper_pearson.py
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 <=
You can’t perform that action at this time.