This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const normalizeStart = (length: number, start: number | undefined): number => { | |
start = start ?? 0; | |
if (start < 0) { | |
start = start + length; | |
} else if (start < -length) { | |
start = 0; | |
} else if (start >= length) { | |
start = length; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Minimal implementation of Redux createStore, with thunkish behavior. | |
*/ | |
import subject from './micro-subject' // see micro-subject.js gist | |
/** | |
* @template T | |
* @typedef {import('./subject').Subject<T>} Subject | |
*/ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Provide basic subscribe/notify/unsubscribe functionality in a | |
* dozen or so lines of code. | |
*/ | |
/** | |
* @template T | |
* @typedef {(value?: T) => void} ObserverFn | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// entropy.js MIT License © 2014 James Abney http://github.com/jabney | |
/*************************************** | |
* ES2015 | |
***************************************/ | |
// Shannon entropy in bits per symbol. | |
function entropy(str) { | |
const len = str.length | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setOps.js MIT License © 2014 James Abney http://github.com/jabney | |
// Set operations union, intersection, symmetric difference, | |
// relative complement, equals. Set operations are fast. | |
(function(so) { | |
'use strict'; | |
var uidList = [], uid; | |
// Create and push the uid identity method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const crypto = require("crypto"); | |
/** | |
* @param {string|number} [seed] | |
* @param {number} [offset] | |
*/ | |
const createRng = (seed = 0, offset = 0) => { | |
const numBytes = 6; // 48 bits | |
const maxInt = 2 ** 48; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IValueCache<T> { | |
get: () => T; | |
invalidate: () => void; | |
} | |
/** | |
* A simple cache that invalidates based on a timer. Every access of | |
* the value will refresh the timer. | |
* | |
* Even this simple class can be broken up into useful pieces and then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An experimental view that can iterate over a subset of an array. | |
* - Not unit tested, there are undoubtedly bugs. | |
*/ | |
"use strict"; | |
const clamp = (min: number, max: number, value: number) => { | |
return Math.min(max, Math.max(min, value)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <chrono> | |
#include <iomanip> | |
#include <iostream> | |
#include <numeric> | |
#include <thread> | |
#include <vector> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Minimal implementation of react-redux style provider and connect function. | |
*/ | |
import React, { useState, useEffect, useContext } from 'react' | |
const StoreContext = React.createContext(null) | |
/** | |
* Wraps root component for providing store context, e.g., | |
* |
NewerOlder