Skip to content

Instantly share code, notes, and snippets.

@antimatter15
antimatter15 / lambdu.py
Last active September 14, 2018 22:57
Jupyter Magic to Invoke Cell as AWS Lambda
FUNCTION_NAME = 'parallel_lambda'
LAMBDA_ROLE = 'arn:aws:iam::972882471061:role/lambda_exec_role'
DEFAULT_MEMORY = 128
DEFAULT_TIMEOUT = 30
AWS_PROFILE = 'paralambda'
NUM_THREADS = 1000
import boto3
import subprocess
import json
@antimatter15
antimatter15 / pairing.js
Created November 30, 2016 05:36
Szudzik's Elegant Pairing Function
// Szudzik's Elegant Pairing Function
// http://szudzik.com/ElegantPairing.pdf
function pair(x,y){
return y > x ? (y*y+x) : (x*x+x+y);
}
function unpair(z){
var q = Math.floor(Math.sqrt(z)),
l = z - Math.pow(q, 2);
@antimatter15
antimatter15 / index.html
Last active September 2, 2018 12:01
FakeTalk
<title>FakeTalk</title>
<style>
body {
background: #eee;
}
* {
box-sizing: border-box;
}
.paper {
padding: 10px;
@antimatter15
antimatter15 / json3.js
Last active August 30, 2018 20:36
json2.js in the third dimension
// author: Kevin Kwok, based on Rose Curve by Eduard Bespalov
// license: The Software shall be used for Good, not Evil.
function main(params) {
var radius = 20,
vec = new CSG.Vector3D(0, 6, 0),
angle;
angle = 360 / 4;
var pent = CSG.Polygon.createFromPoints([
thing
= (list 1 2 3 4)
= (1 . (2 . (3 . (4 . nil))))
(car thing)
= 1
(cdr thing)
= (2 . (3 . (4 . nil)))
= cdr_thing

Experiments with Reverse Mode Auto-Differentiation

Auto Differentiation is a technique used to calculate gradients of arbitrary computer programs. As opposed to symbolic differentiation, which occasionally results in an exponential blow-up in the size of the programs, and numerical differentiation, which estimates the gradient by running the target program dozens or hundreds of times, auto differentiation allows you to get out the gradient of a program after a single pass.

Reverse Mode Auto-Differentiation, especially in its imperative form has recently gained popularity due to projects like TF Eager, PyTorch, and HIPS Autograd. Existing auto differentiation libraries exploit operator overloading capabilities found in many languages to create data structures that incrementally track gradients.

Javascript lacks operator overloads, so defining special data structures loses much of its natural appeal. Rather than thinking about data structures, we can think about functions and how they compose, and how th

Neural Network XOR

@antimatter15
antimatter15 / irpc4.js
Created December 29, 2017 04:47
Interactively invoke remote resources: REST function parameters
// awaitable queue
class AwaitableQueue {
constructor(){
this.queue = []
this.resolvers = []
}
pop(){
if(this.queue.length > 0) return Promise.resolve(this.queue.shift());
return new Promise((resolve, reject) => this.resolvers.push(resolve) )
}
@antimatter15
antimatter15 / irpc.js
Created December 27, 2017 09:17
Continuations over REST
// set up a mock HTTP client/server API
// should be pretty easy to replace this with
// the real ones
var endpoints = {}
async function fetch(path, opts){
let data = await endpoints[path](JSON.parse(opts.body))
return { async json(){ return data } }
}
async function serve(path, fn){
@antimatter15
antimatter15 / Add
Created November 28, 2017 07:55 — forked from carbide-public/Add
import java.util.Scanner;
public class Add implements Comparable<Add>{
private String name;
private String lastName;
private int number;
public Add(String name, String lastName, int number) {
this.name = name;