Skip to content

Instantly share code, notes, and snippets.

@antimatter15
antimatter15 / chatgpt.js
Created Dec 2, 2022
ChatGPT CLI Command Line Interface
View chatgpt.js
#!/usr/bin/env node
const fs = require("fs");
function uuid() {
return [8, 4, 4, 4, 12]
.map((k) =>
Math.random()
.toString(16)
.slice(3, 3 + k)
@antimatter15
antimatter15 / README.md
Created Aug 16, 2021
Arbitrary Base Conversion Algorithm (Javascript)
View README.md

Arbitrary Base Conversion Algorithm

This is a function that can convert between arbitrary bases implemented in both Javascript and Python.

Many existing implementations, such as https://rot47.net/base.html or https://gist.github.com/inflammable/2929362 use a number as the internal representation, and thus can't safely encode/decode more than 8 letters of Base64 encoded text, or 9 letters of Base58 text (which isn't enough for parsing a Bitcoin address).

Other implementations rely on complicated third party libraries for bignum (e.g. https://rosettacode.org/wiki/Non-decimal_radices/Convert#JavaScript).

Several implementations required converting to Uint8Arrays (Base 256) as an intermediate. Others were essentially ports of complicated C implementations (see https://github.com/cryptocoinjs/base-x/blob/master/src/index.js).

@antimatter15
antimatter15 / lambdu.py
Last active Sep 14, 2018
Jupyter Magic to Invoke Cell as AWS Lambda
View lambdu.py
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
View index.html
<title>FakeTalk</title>
<style>
body {
background: #eee;
}
* {
box-sizing: border-box;
}
.paper {
padding: 10px;
@antimatter15
antimatter15 / json3.js
Last active Aug 30, 2018
json2.js in the third dimension
View json3.js
// 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([
@antimatter15
antimatter15 / faketalk.js
Last active Dec 2, 2018
A toy system inspired by realtalk
View faketalk.js
function mouse(_, me, when, claim){
when('fox is out', () => {
claim(me, 'wish', 'labelled', 'squeak')
claim(me, 'wish', 'outlined', 'red')
})
}
function fox(_, me, when, claim){
claim('fox is out')
}
@antimatter15
antimatter15 / dynamic.js
Last active Dec 2, 2018
Dynamic Scoped Javascript
View dynamic.js
// Part I: The Magic
// The crux of this are two methods: pushStackTokens and readStackTokens
// They form the primitives for manipulating the Javascript VM's call stack
// pushStackTokens allows us to inject information (tokens) into the call stack
// readStackTokens allows us to retrieve all the stack tokens in the
// current call stack.
function pushStackTokens(tokens, fn, ...args){
tokens.forEach(tok => console.assert(/^\w+$/.test(tok),
View gist:02674d7e8b16cdf7aeaba52eaec47489
thing
= (list 1 2 3 4)
= (1 . (2 . (3 . (4 . nil))))
(car thing)
= 1
(cdr thing)
= (2 . (3 . (4 . nil)))
= cdr_thing
View autodiff.md

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

@antimatter15
antimatter15 / irpc4.js
Created Dec 29, 2017
Interactively invoke remote resources: REST function parameters
View irpc4.js
// 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) )
}