Skip to content

Instantly share code, notes, and snippets.

View stereobooster's full-sized avatar
🇺🇦
stand with Ukraine

stereobooster

🇺🇦
stand with Ukraine
View GitHub Profile
const reducer = (oldState, action) => {
if (typeof action === "function") {
return action(oldState)
} else {
return action;
}
}
// useState is simplified useReducer
const useState = (initialState, init) => {
/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
*/
function deepFreeze<T>(object: T, path?: string): Readonly<T> {
const propNames = Object.getOwnPropertyNames(object);
let latest;
try {
for (const name of propNames) {
// @ts-ignore - do not verify implementation
// z85 alphabet - doesn't include ', ", \
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
const base = alphabet.length;
const base85 = input => {
const result = [];
do {
const remainder = input % base;
input = ~~(input / base);
result.push(alphabet[remainder]);
} while (input != 0);

Knowledge structure

  • Maps, Graphs, Mind Maps
  • Roadmap, curriculum
  • Dictionary, encyclopedia
  • Abstractions, analogy
  • alphabet, building blocks

Maps