Skip to content

Instantly share code, notes, and snippets.

View wspringer's full-sized avatar

wilfred@eastpole.nl wspringer

View GitHub Profile
@wspringer
wspringer / isEven.js
Created May 21, 2023 10:02
Pointless isEven functions are the cat videos of code
/**
* Because the Internet
*/
const isEven = (x) => {
const ys = (x >>> 0).toString(2).split("");
return ys[ys.length - 1] !== ys[0];
};
@wspringer
wspringer / lists.ts
Last active December 20, 2022 14:47
Simple single linked list in TypeScript.
export type List<T> = { value: T; next: List<T> } | null;
export const map = <T, U>(list: List<T>, fn: (value: T) => U): List<U> => {
if (list === null) return null;
return {
value: fn(list.value),
next: map(list.next, fn),
};
};
@wspringer
wspringer / machine.js
Last active May 7, 2020 12:45
Generated by XState Viz: https://xstate.js.org/viz
const ConsumerTransferFlowMachine = Machine(
{
id: 'ConsumerTransfer',
initial: 'in_progress',
context: {
actionDate: 3
},
states: {
in_progress: {
on: {
@wspringer
wspringer / machine.js
Last active May 7, 2020 12:40
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
{
"swagger": "2.0",
"host": "localhost:8080",
"basePath": "/",
"schemes": ["http"],
"info": { "title": "EBT Documentation", "version": "0.0.1" },
"tags": [],
"paths": {
"/ebt": {
"post": {
{
"swagger": "3.0",
"host": "localhost:8080",
"basePath": "/",
"schemes": ["http"],
"info": { "title": "EBT Documentation", "version": "0.0.1" },
"tags": [],
"paths": {
"/ebt": {
"post": {
@wspringer
wspringer / machine.js
Last active March 29, 2020 14:15
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
let bottles = (number) => switch(number) {
| 0 => "no more bottles of beer"
| 1 => "1 bottle of beer"
| n => {
let formatted = string_of_int(n);
{j|$formatted bottles of beer|j};
}
}
let rec countdownFrom = (current) => current == 0 ? {
@wspringer
wspringer / machine.js
Created December 13, 2019 14:06
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
import jwt from 'jsonwebtoken'
import { certToPEM } from './utils'
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function latestKeys() {
console.log('Fetching latest')
const latest = await fetch(