Skip to content

Instantly share code, notes, and snippets.

@antimatter15
antimatter15 / slowblake512.js
Created July 1, 2024 02:23
Slow BLAKE-512 Implementation using BigUint64Array
// BLAKE512 JavaScript Implementation
// Uint64Blake x 4,512 ops/sec ±1.20% (98 runs sampled)
// RegularBlake x 534,660 ops/sec ±1.31% (95 runs sampled)
// This one is 100x slower than the blake-hash implementation.
const sigma = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
[14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
[11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
@antimatter15
antimatter15 / console.image.js
Created November 30, 2023 01:47
console.image and console.plot
console.image = (url) => {
fetch(url)
.then(res => res.blob())
.then(blob => new Promise(resolve => {
let fr = new FileReader()
fr.onload = () => resolve(fr.result)
fr.readAsDataURL(blob)
}))
.then(url => new Promise(resolve => {
let img = new Image()
@antimatter15
antimatter15 / chatgpt.js
Created December 2, 2022 23:38
ChatGPT CLI Command Line Interface
#!/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 August 16, 2021 06:21
Arbitrary Base Conversion Algorithm (Javascript)

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 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 / 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([
@antimatter15
antimatter15 / faketalk.js
Last active December 2, 2018 23:37
A toy system inspired by realtalk
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 December 2, 2018 23:43
Dynamic Scoped Javascript
// 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),
thing
= (list 1 2 3 4)
= (1 . (2 . (3 . (4 . nil))))
(car thing)
= 1
(cdr thing)
= (2 . (3 . (4 . nil)))
= cdr_thing