Skip to content

Instantly share code, notes, and snippets.

View chrisfrazier0's full-sized avatar

Chris Frazier chrisfrazier0

View GitHub Profile
@chrisfrazier0
chrisfrazier0 / avl.go
Last active January 10, 2021 18:08
AVL Tree Implementation in Go
package avl
type Compareable interface {
Compare(Compareable) int8 // 0 equal, -1 less than, 1 greater than
}
type Node struct {
Data []Compareable // duplicates allowed, data stored as array
Balance int8 // negative left heavy, positive right heavy
Link [2]*Node // 0 left, 1 right
@chrisfrazier0
chrisfrazier0 / isometric.js
Created January 10, 2021 18:10
Cartesian to Isometric and back
function ctoi(x, y) {
return {
x: x-y,
y: (x+y)/2,
}
}
function itoc(x, y) {
return {
x: (2*y+x)/2,
@chrisfrazier0
chrisfrazier0 / 0 LICENSE
Last active November 5, 2021 01:38
ECC: Ed448 - Goldilocks
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.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@chrisfrazier0
chrisfrazier0 / BigNum.ts
Created February 5, 2022 21:16
BigNum -- Arbitrarily large integers
const UINT32_MAX_VALUE = 0xFFFFFFFF
class BigNum {
private _positive!: boolean
private _limbs!: Uint32Array
constructor(positive: boolean | string = true, limbs: Uint32Array | number[] = []) {
if (typeof positive === 'string') {
return BigNum._fromString(positive)
}
@chrisfrazier0
chrisfrazier0 / example.js
Last active April 11, 2022 13:46
Parser Example
/*
expression = term {('+' | '-') term}
term = factor {('*' | '/') factor}
factor = base ['^' factor]
base = ['-'] value
value = number | '(' expression ')'
number = integer ['.' fractional]
integer = '0' | onenine {digit}
fractional = digit {digit}
onenine = digit - '0'
@chrisfrazier0
chrisfrazier0 / 0_fibonacci.b
Last active April 19, 2022 15:08
Fibonacci Brainfuck
[
main() {
return print(fib(10))
}
fib(n) {
if (n == 0) {
return 0
} else if (n == 1) {
return 1
@chrisfrazier0
chrisfrazier0 / FOML.js
Created June 14, 2022 14:48
Frazier's Object Modeling Language (FOML)
/**
* Frazier's Object Modeling Language (FOML)
*
* FOML is a superset of JSON with...
* 1. Bash style comments
* 2. Root object curley braces are optional (each FOML document describes a single object)
* 3. End of line commas are optional, trailing commas are allowed
* 4. Colon (:) and equal (=) are interchangeable
* 5. Colon/equal is optional for object and array assignment
* 6. Simple property names do not require quotes (alphanumeric and _-.$@ characters only)
const make_regexp = function(str, fl) {
return new RegExp(str.replace(/\s/g, ''), fl)
}
const rx_number = make_regexp(`^(?:
0 (?:
b [01]+
| o [0-7]+
| x [0-9 A-F]+
| \\. [0-9]+ (?: e [+\\-]? [0-9]+ )?
@chrisfrazier0
chrisfrazier0 / 0 custom.js
Created September 9, 2022 16:15
Custom Operators
const operations = {
'+': {
precedence: 1,
handler: (x, y) => x + y,
},
'-': {
precedence: 1,
handler: (x, y) => x - y,
},
class AnimationLoop {
constructor({ update, render, panic, tickRate = 30, autoPause = true }) {
this.update = update
this.render = render
this.panic = panic ?? (() => this.delta = 0)
this.frameID = null
this.lastFrameMs = 0
this.lastFpsMs = 0
this.frameCount = 0
this.fps = 60