Skip to content

Instantly share code, notes, and snippets.

View bever1337's full-sized avatar

bever1337 bever1337

View GitHub Profile
@bever1337
bever1337 / eracer.ts
Last active June 15, 2023 05:59
Functional event loops
const target = new EventTarget();
setInterval(() => {
target.dispatchEvent(new Event("event-a"));
}, 3333);
setInterval(() => {
target.dispatchEvent(new Event("event-b"));
}, 4444);
@bever1337
bever1337 / achaea-map.xsl
Last active May 13, 2023 07:54
Convert IRE XML Maps to JSON using XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/">
<xsl:text>{"areas":[</xsl:text>
<xsl:for-each select="/map/areas/area">
<xsl:text>{"id":"</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>","name":"</xsl:text>
<xsl:value-of select="@name" />
@bever1337
bever1337 / another-text-widget.js
Created June 30, 2022 18:08
Netlify CMS text widget where user may toggle between 'string' and 'text' widget controls.
import CMS from "netlify-cms-app";
import { createElement, useState } from "react";
const widget = {
control: BetterTextWidgetControl,
name: "betterTextWidget",
preview: BetterTextWidgetPreview,
};
export default widget;
@bever1337
bever1337 / fetch.js
Created May 14, 2022 20:35
Simple caching in workers and the browser
/**
* @module
* Window and worker friendly fetch caching
*/
import { CACHE_NAME } from "./constants";
/**
* Always sends the fetch request and the response is always cached. The cache is never read.
* This is useful if a non-cached response is required, but the cache should still be updated
@bever1337
bever1337 / machine.js
Last active May 17, 2022 02:48
Teeny-Weeny Iterable Finite State Machine
/**
* @template StateKey - Any value used to index a Map of Q
* @template Transition - Any value used to index a Map of Transitions and an undefined value is an epsilon acceptor. Non-epsilon transitions are attempted first
* @param {Map<StateKey & any, Map<Transition | undefined, ((transition?: any & StateKey) => StateKey)>>} Q - Where q0 is first q in Q, and final states are q in Q with empty transitions
* @returns {Iterable<StateKey>} - Iterable machine where `machine.next(transition)` steps machine and returns next q.
*/
export function dfaFactory(Q) {
/** @type {StateKey} */
const q0 = Q.keys().next().value;
let q = q0;
@bever1337
bever1337 / README.md
Last active May 14, 2022 20:06
A request router for browser and edge environments

Request Response Router

API

Router

A Router is a stateful container for an array of (Request, Response) tuples.

The following:

@bever1337
bever1337 / lazy-named-export.js
Last active September 30, 2022 17:06
A little glue to support named exports with React.lazy
// Returns all named exports as though they were dynamic default exports
// https://reactjs.org/docs/code-splitting.html#named-exports
import { lazy } from 'react';
/**
* @function lazyNamedExport
* @param {function} dynamicImportCallback
* @param {string} exportKey
* @description Returns all named exports as though they were dynamic default exports
@bever1337
bever1337 / windowsBootUSBGuide.md
Last active March 25, 2023 19:12
Creating a Windows 10 bootable USB for PCs using MacOS Catalina and Parallels

Creating a Windows 10 bootable USB for PCs using MacOS Catalina and Parallels

Mac users who want to dual-boot into Windows 10 use the Boot Camp Assistant to create legitimate bootable Windows 10 USBs. Unfortunately, these drives will only work on Mac machines. To create a Windows 10 bootable USB for PCs, some extra work is necessary. I used these steps to create a Windows 10 bootable USB on a macbook pro running Catalina so that I could install Windows 10 on a Lenovo ThinkCentre m900 Tiny.

Downloading and install the required files to your MacOS machine