Skip to content

Instantly share code, notes, and snippets.

View Floofies's full-sized avatar
🧩
Looking for a job

Dani Glore Floofies

🧩
Looking for a job
View GitHub Profile
@Floofies
Floofies / unitTest.ts
Created March 16, 2024 00:05
Low budget unit tests instead of Jasmine or Chai. Isolates between invocations. Safely contains everything that can go wrong.
export default function unitTest (description:string, testFunction:Function):void {
const testLog:Array<string> = [`Test: ${description}:`];
const expectQueue:Array<Function> = [];
class Expectation {
actualValue;
constructor(anyValue: any) {
this.actualValue = anyValue;
return this;
}
toBe(expectedValue: any) {
@Floofies
Floofies / MVVM2.ts
Last active April 19, 2023 18:42
Tiny MVVM in TypeScript with shallow diffing/binding
// Object storage with publisher/subscriber model for updates.
type State = null|object;
export class DataStore {
state:State;
oldState:State;
subscribers:Map<number|string, Set<Function>>;
constructor(state: State = null) {
this.state = {};
this.oldState = {};
this.subscribers = new Map();
@Floofies
Floofies / list2string.dm
Last active March 9, 2023 07:28
Return string representation of every value in the given list. Traverses sub-lists to provide every reachable value.
/// Return string representation of every value in the given list.
/// Traverses sub-lists to provide every reachable value.
/proc/list2string(root)
var/str = "Travsersal Tree for `[root]`:\n"
var/list/seen_lists = list("\ref[root]")
var/list/runqueue = list()
var/list/waitqueue = list()
waitqueue[root] = list("root", " ")
while(length(waitqueue))
runqueue = waitqueue.Copy()
@Floofies
Floofies / MemManager.js
Created April 7, 2021 14:37
Object Oriented Memory Manager
function MemManager(constructor, free, min, max, args = null) {
this.pool = [];
this.free = poolObj => {
if (!poolObj[MemManager.allocSym]) return;
poolObj[MemManager.allocSym] = false;
free(poolObj);
this.pool.push(poolObj);
};
this.objConstructor = constructor;
this.args = args;
@Floofies
Floofies / duke-nukem-quotes.json
Last active December 28, 2022 15:39
Duke Nukem Quotes
[
{
"quote":"It's time to kick ass and chew bubble gum. And I'm all out of gum.",
"author":"Duke Nukem"
},
{
"quote":"Damn, those alien bastards are gonna pay for shooting up my ride.",
"author":"Duke Nukem"
},
{
const Hz = require("hertzscript-vm");
const performance = require("perf_hooks").performance;
// Lazy Caterer's Sequence
const src1 = `
var total = 1;
const numbers = [1];
while (total < 200) {
numbers.push(numbers[numbers.length - 1] + total);
total++;
}
@Floofies
Floofies / hzIterator.js
Created December 1, 2019 23:14
Compiler Output Test
for (const foo of bar) {
// Source
}
// Transform to equivalent of:
const hzIterator = bar();
while(true) {
const hzIteratorState = hzIterator.next();
if (hzIteratorState.done) break;
@Floofies
Floofies / VPM_Wikipedia.txt
Last active November 26, 2019 18:50
Voluntary Preemptive Multitasking section for Wikipedia
=== Voluntary Preemption ===
Voluntary Preemption is most simply described as a hybrid combination of both cooperative multitasking and preemptive multitasking.
Voluntary Preemption is implemented via a source code compilation technique whereby a source-to-source compiler implements an analogue to preemption via the automatic insertion of cooperative yields; such a compiler produces newly re-entrant programs which effectively replicate the behavior of preemption.<ref>{{cite journal |author-first1=Abha |author-last1=Moitra |title=Voluntary Preemption: A Tool In The Design Of Hard Real-Time Systems |journal=International Symposium on Formal Techniques in Real-Time and Fault-Tolerant Systems, Second International Symposium Nijmegen, The Netherlands, January 8–10, 1992 Proceedings |pages=87–106}}</ref>
To implement Preemptive Multitasking via Voluntary Preemption, a compiler analyzes source code using a process calculus algorithm which predicts the amount of time a process will control the processor; location
@Floofies
Floofies / Channel.js
Created October 17, 2019 19:35
Channel Prototype
function Channel(limit = 0) {
this.limit = limit;
this.buffer = [];
this.readers = [];
this.wakeRead = null;
this.wakeWrite = null;
this.readPromise = null;
this.writePromise = null;
}
Channel.prototype.waitForRead = function() {
@Floofies
Floofies / testDiff.js
Created October 26, 2018 06:37
Returns true if obj1 differs in any way from obj2
// Returns true if obj1 differs in any way from obj2
function testDiff(obj1, obj2) {
if (obj1 === null) return obj1 !== obj2;
const stack = [{ obj1: obj1, obj2: obj2 }];
const seen = new Map();
seen.set(obj1, stack[0]);
_objects: while (stack.length !== 0) {
const objects = stack.pop();
if (Array.isArray(objects.obj1) !== Array.isArray(objects.obj2)) return true;
const props1 = Object.keys(objects.obj1);