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
declare const brand: unique symbol | |
export type Brand<T, TBrand> = T & { [brand]: TBrand } |
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
function youSayGoodbyeISayHello<TGreeting extends 'hello' | 'goodbye'>(greeting: TGreeting) { | |
const returned = greeting === "goodbye" | |
? "hello" | |
: "goodbye" | |
return returned as TGreeting extends 'hello' ? 'goodbye' : 'hello'; | |
} |
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
export class Stack<T> implements Iterable<T> { | |
#arr: Array<T> = [] | |
constructor(arr?: Array<T>) { | |
if (arr) { | |
this.#arr = arr.slice() | |
} | |
} | |
push(el: T): void { | |
this.#arr.push(el) |
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
import Yallist from 'yallist' | |
const intermittentDrummer = const mkStepwand = ({ delay = 1000, delta = 200, breads = [] }: { delay?: number; delta?: number; breads?: Array<Bread> }) => { | |
const indians = new Yallist<{ goodFor: number; bread: Bread }>() | |
let dontStop = true | |
const steps = () => indians.toArray().map(el => el.bread) | |
const dates = () => indians.toArray().map(el => el.goodFor) | |
// pre feeed |
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
import Yallist from 'yallist' | |
import { setTimeout } from 'timers/promises' | |
type Bread = { | |
[key: string]: string; | |
} | |
const mkStepwand = ({ delay = 1000, delta = 200, breads = [] }: { delay?: number; delta?: number; breads?: Array<Bread> }) => { | |
const indians = new Yallist<{ goodFor: number; bread: Bread}>() | |
let dontStop = true |
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 minimist = require('minimist'); | |
console.log(`text=${text}`) | |
// https://stackoverflow.com/questions/16261635/javascript-split-string-by-space-but-ignore-space-in-quotes-notice-not-to-spli#answer-46946490 | |
const idxAt = text.indexOf(' ') | |
const arg = text | |
.slice(idxAt + 1) | |
.match(/\\?.|^$/g) | |
.reduce((p, c) => { |
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 machine = Machine({ | |
id: 'lightbulb', | |
initial: 'unlit', | |
states: { | |
lit: { | |
on: { | |
TOGGLE: 'unlit', | |
BREAK: 'broken' | |
} | |
}, |
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 wbi = JSON.parse(message) | |
const wid = wbi.key.id | |
const fromMe = wbi.key.fromMe | |
const remoteJid = wbi.key.remoteJid.split('@s.whatsapp.net')[0] | |
const participant = wbi.participant | |
? wbi.participant.split('@s.whatsapp.net')[0] | |
: undefined | |
const isCallMissed = wbi.messageStubType === 'CALL_MISSED_VOICE' | |
if (isCallMissed) { |
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 Redis = require('ioredis') | |
const redisConn = process.env.REDIS_CONN | |
const hardid = process.env.HARDID | |
const panoptickey = 'zap:panoptic' | |
const catcherrKey = 'zap:catcherr' | |
const actbooting = JSON.stringify({ type: 'booting', hardid, timestamp: Date.now() }) | |
const mkactbigerr = ({ err }) => JSON.stringify({ type: 'bigerr', hardid, err, timestamp: Date.now() }) |
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 delay = t => new Promise(res => setTimeout(() => res(), t)) | |
const arr = Array(5).fill() | |
const delayed = async function* delayed(arr, t = 1000) { | |
for(const el of arr) { | |
yield delay(t) | |
} | |
} |
NewerOlder