Skip to content

Instantly share code, notes, and snippets.

declare const brand: unique symbol
export type Brand<T, TBrand> = T & { [brand]: TBrand }
function youSayGoodbyeISayHello<TGreeting extends 'hello' | 'goodbye'>(greeting: TGreeting) {
const returned = greeting === "goodbye"
? "hello"
: "goodbye"
return returned as TGreeting extends 'hello' ? 'goodbye' : 'hello';
}
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)
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
@itacirgabral
itacirgabral / genpub.ts
Last active February 27, 2022 21:52
typescript async generator operator
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
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) => {
@itacirgabral
itacirgabral / machine.js
Created September 29, 2021 04:43
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'lightbulb',
initial: 'unlit',
states: {
lit: {
on: {
TOGGLE: 'unlit',
BREAK: 'broken'
}
},
@itacirgabral
itacirgabral / index.js
Created March 28, 2021 16:23
punkdrummer
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) {
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() })
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)
}
}