Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick Smith BurntCaramel

View GitHub Profile
@BurntCaramel
BurntCaramel / 1.js
Last active Dec 1, 2021
Mini modules
View 1.js
/**
* Pi to 8 decimal places
*/
export const pi = 3.14159265;
export const dateFormat = "YYYY/MM/DD";
export const isEnabled = true;
export const flavors = ["vanilla", "chocolate", "caramel", "raspberry"];
@BurntCaramel
BurntCaramel / timing.ts
Last active Dec 2, 2021
Debouncing with logical clocks in React
View timing.ts
import { DispatchWithoutAction, useEffect, useMemo, useReducer } from 'react';
import type { DependencyList, EffectCallback } from 'react';
/**
* A logical clock.
*
* @returns a tuple with the current clock value, and a stable function that advances the clock.
*/
export function useTicker(): [number, DispatchWithoutAction] {
return useReducer(n => n + 1, 0);
@BurntCaramel
BurntCaramel / example.js
Created Sep 11, 2021
`in` as pipeline keyword
View example.js
// See: https://twitter.com/buildsghost/status/1436394640861646848
envars
|> Object.keys(in)
|> in.map(envar => `${envar}=${envars[envar]}`)
|> in.join(' ')
|> `$ ${in}`
|> chalk.dim(in, 'node', args.join(' '))
|> console.log(in)
@BurntCaramel
BurntCaramel / main.md
Last active Sep 3, 2021
RxJS Loading Patterns
View main.md

RxJS Loading Patterns

Observable creators

of(A...) => Observable<A>

Create an observable emitting each item passed in.

from(Promise<A> | Iterable<A>) => Observable<A>

@BurntCaramel
BurntCaramel / init.lua
Last active Jan 11, 2022
My Hammerspoon config
View init.lua
require("hs.ipc")
hs.ipc.cliInstall()
local math = require("hs.math")
currentSpeech = nil
mouseCircle = nil
mouseCircleTimer = nil
@BurntCaramel
BurntCaramel / actor-protocol.swift
Last active Mar 31, 2021
Defining Actors in Swift with Protocols
View actor-protocol.swift
protocol Actor : AnyObject, Sendable {
associatedtype State
isolated var state: State
}
struct BankAccountState {
var balance: Double
mutating func deposit(amount: Double) {
@BurntCaramel
BurntCaramel / soonerorlater.test.ts
Last active Feb 20, 2021
Parse natural language date span
View soonerorlater.test.ts
import { parse } from "./index";
test("parse()", () => {
test.each([
['Monday', { weekdays: new Set(['monday']) }],
['Wednesday', { weekdays: new Set(['wednesday']) }],
[' Wednesday ', { weekdays: new Set(['wednesday']) }],
['Wednesday and Saturday', { weekdays: new Set(['wednesday', 'saturday']) }],
['Wednesday or Saturday', { weekdays: new Set(['wednesday', 'saturday']) }],
['Wednesday, Saturday', { weekdays: new Set(['wednesday', 'saturday']) }],
View machine.js
const pedestrianStates = {
initial: 'walk',
states: {
walk: {
on: {
PED_COUNTDOWN: 'wait'
}
},
wait: {
on: {
View keybase.md

Keybase proof

I hereby claim:

  • I am burntcaramel on github.
  • I am burntcaramel (https://keybase.io/burntcaramel) on keybase.
  • I have a public key ASArnj22CZ7v-9tbcz-52hippT2ZfvGy4dQ3ZoSelHe3lwo

To claim this, I am signing this object:

@BurntCaramel
BurntCaramel / 1.ts
Created Jun 29, 2018
React state management ideas
View 1.ts
interface State {
counter: number
}
const counterModel = {
initial(): State {
return {
counter: 0
};
},