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
class Stats { | |
periods = 0 | |
totals = {} as Record<string, number> | |
starts = {} as Record<string, number> | |
start(name: string) { | |
this.starts[name] = performance.now() | |
} | |
end(name: string) { | |
if (!this.starts[name]) throw new Error(`No start for ${name}`) |
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 { useCallback, useEffect, useMemo } from 'react' | |
export class Poller<T> { | |
private interval: ReturnType<typeof setInterval> | null = null | |
constructor( | |
private readonly callback: (arg: { didCancelRef: { current: boolean } }) => T, | |
private readonly intervalMs: number | |
) {} | |
readonly didCancelRef = { current: false } | |
start() { |
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
{ | |
"vim.easymotion": true, | |
"vim.leader": "<space>", | |
"files.autoSave": "afterDelay", | |
"editor.formatOnSave": true, | |
"editor.codeActionsOnSave": ["source.addMissingImports"], | |
"vim.visualModeKeyBindingsNonRecursive": [ | |
{ | |
"before": ["<leader>", "g"], | |
"commands": ["editor.action.smartSelect.grow"] |
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 { existsSync, readFileSync, statSync, writeFileSync } from 'fs' | |
import glob from 'glob' | |
import path from 'path' | |
import { parse, print, visit } from 'recast' | |
const extensions = ['.js', '.mjs', '.cjs'] | |
function resolveRelativePath(importingFile: string, relativePath: string) { | |
if (!relativePath.startsWith('.')) { | |
return relativePath | |
} |
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 React, { useContext, useEffect, useMemo, useState } from "react" | |
type ProviderComponent<T> = React.FC<{ initialValue: T }> | |
interface PrivateContextValue<T> { | |
useGlobalStateProxy(): T | |
} | |
class GlobalStateContext<T> { | |
constructor(private context: React.Context<PrivateContextValue<T>>, public Provider: ProviderComponent<T>) {} | |
} | |
/** |
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
#!/bin/bash | |
DAYS_SINCE_LAST_CHANGE=14 | |
TOTAL_BYTES_REMOVED=0 | |
Mb=1000000 | |
Kb=1000 | |
node_modules=$(find . -name "node_modules" -type d -prune) |
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
#!/usr/bin/env node | |
# run this before using: yarn add --dev node-pty semver | |
const os = require("os") | |
const pty = require("node-pty") | |
const semver = require("semver") | |
function semverComparator(a, b) { | |
if (semver.lt(a, b)) { |
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 d = require("derivable") | |
const name = d.atom("World"); // the name of the user | |
const countryCode = d.atom("en"); // for i18n | |
// static constants don't need to be wrapped | |
const greetings = { | |
en: "Hello", | |
de: "Hallo", | |
es: "Hola", |
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
// Welcome! require() some modules from npm (like you were using browserify) | |
// and then hit Run Code to run your code on the right side. | |
// Modules get downloaded from browserify-cdn and bundled in your browser. | |
var patch = require('snabbdom').init([ | |
require('snabbdom/modules/props'), | |
]); | |
var h = require('snabbdom/h'); | |
var elem = h('div', [ |
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
List( | |
Map( | |
"id" -> "d979c0f0c2f4b1ec310aff3ff48f75aa4e54c07752ae4fb76161739c6fd2980a2f0f7c469706aac421c449336f34147b8d72f89e2ecd6e7c6e286395a6548b7d", | |
"timestamp" -> "1462452325349", | |
"name" -> "Haim", | |
"country" -> "Curacao", | |
"amount" -> "4571.62" | |
), | |
Map( | |
"id" -> "857f1e5f2b8c0683aa450970dcf8c528e3fa87a9bf56e046b6b7ca5560ca0a76dd555b6666b88c35d908980218915e203882edc1fe79af6687d612357625e6e8", |
NewerOlder