Skip to content

Instantly share code, notes, and snippets.

View jdpage's full-sized avatar
💭
random walk

Jonathan David Page jdpage

💭
random walk
View GitHub Profile
@jdpage
jdpage / notify_deco.py
Created July 23, 2019 03:10
Handy function decorator for completion notification in e.g. Jupyter Notebooks
# A nestable function-completion notification decorator
# File: notify_deco.py
# Author: Jonathan David Page <jonathan@sleepingcyb.org>
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#include <stdlib.h>
#include <unistd.h>
#define BUFSIZE 1024
int main()
{
/* Pipe text into me! */
char data[BUFSIZE + 4];
@jdpage
jdpage / hex.h
Created October 13, 2018 21:12
proposed hex board API
#ifndef HEX_HEX_H
#define HEX_HEX_H
#include <stdlib.h>
enum hex_err_e {
HEX_OK,
HEX_ENOMEM,
HEX_EBOUNDS,
HEX_EBADSPACE,

Keybase proof

I hereby claim:

  • I am jdpage on github.
  • I am jdpage (https://keybase.io/jdpage) on keybase.
  • I have a public key whose fingerprint is 2EAF E6DF 2116 2473 BF75 009B D024 E567 FFB1 9848

To claim this, I am signing this object:

@jdpage
jdpage / gist:5e0a316fcafd24a8fb23
Last active August 29, 2015 14:02
Two-Octave Shepherd Organ
// octave count?
2 => int octaves;
// device to open
0 => int device;
// get from command line
if( me.args() ) me.arg(0) => Std.atoi => device;
MidiIn min;
MidiMsg msg;
@jdpage
jdpage / gist:5418032
Created April 19, 2013 03:52
C continuation passing
#include <stdio.h>
#include <stdlib.h>
#define NEXT(n) ((n)->next(n))
typedef struct co_fib {
int (*next)(struct co_fib *);
int a;
int b;
} * co_fib_t;
@jdpage
jdpage / approx_cofr.py
Created December 20, 2012 04:55
Better way of getting fractional pi approximations. See the corresponding blog post at http://sleepingcyb.org/2012/12/20/approximating-pi-redux for an explanation.
from __future__ import division
from fractions import gcd
from itertools import izip, tee, izip_longest
import sys
def pi_noncanon_seq():
"""
produces a generalized continued fraction from of pi, starting with
(0 4) (1 1) (3 4) (5 9) ...
"""
@jdpage
jdpage / Add.java
Created June 30, 2012 18:42
Playing Haskell (in Java)
class Add extends Func2<Integer, Integer, Integer> {
@Override
public Integer apply(Integer a, Integer b) {
return a + b;
}
}
@jdpage
jdpage / sort.py
Created March 28, 2012 03:13
Quicksort in Python
#!/usr/bin/python3
import random
def sorted(l):
if len(l) == 0:
return l
else:
x, *xs = l
left, right = [], []
@jdpage
jdpage / sort.fs
Created March 28, 2012 02:58
Quicksort in F#
open System
let rec sorted = function
| (x :: xs) ->
let left, right = List.partition (fun i -> i < x) xs
let sleft = sorted left
let sright = sorted right
sleft @ (x :: sright)
| [] -> []