Skip to content

Instantly share code, notes, and snippets.

View colinhacks's full-sized avatar

Colin McDonnell colinhacks

View GitHub Profile
import Benchmark from "benchmark";
const datetimeValidationSuite = new Benchmark.Suite("datetime");
const DATA = "2020-01-01";
const MONTHS_31 = new Set([1, 3, 5, 7, 8, 10, 12]);
const MONTHS_30 = new Set([4, 6, 9, 11]);
const simpleDatetimeRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
const datetimeRegexNoLeapYearValidation =
@colinhacks
colinhacks / index.tsx
Created September 14, 2023 20:52
CrappyNext.js
import { renderToString } from "react-dom/server";
const router = new Bun.FileSystemRouter({
style: "nextjs",
dir: "./pages",
});
Bun.serve({
port: 3000,
development: true,
@colinhacks
colinhacks / package.json
Last active September 8, 2023 16:55
Script runner benchmark
{
"name": "sayhi",
"module": "index.ts",
"type": "module",
"dependencies": {
"cowsay": "^1.5.0"
},
"scripts": {
"hi": "echo 'hi'"
}
@colinhacks
colinhacks / bench.sh
Last active January 5, 2024 09:37
Benchmark testing libraries against Zod's test suite
# requires hyperfine and Bun v0.7 or later
# https://github.com/sharkdp/hyperfine
git clone git@github.com:colinhacks/zod.git
cd zod
bun install
hyperfine --warmup 3 --runs 10 \
"bun test src" \
"npx vitest --config configs/vitest.config.ts" \
"npx jest -c configs/babel-jest.config.json" \
@colinhacks
colinhacks / index.html
Created May 13, 2022 04:13
Minimal docsify index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>user/repo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta
name="description"
content="This is a description of user/repo"
/>
@colinhacks
colinhacks / log_json_shortcuts.json
Created January 16, 2022 23:50
VSCode shortcuts for console.log and JSON.stringify
// keybindings.json
// Command Pallette > Open Keyboard Shortcuts (JSON)
[
{
"key": "cmd+shift+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log(${TM_SELECTED_TEXT}$1)$0;"
@colinhacks
colinhacks / ultimate_eslint.md
Last active April 23, 2021 03:12
Ultimate ESLint + Prettier setup

The Ultimate ESLint and Prettier setup

Featuring:

  • TypeScript support
  • Prettier auto-formatting
  • auto-removal of unused imports
  • auto-sorting of all imports
  • auto-consolidation of imports

Install deps

type Generics = Partial<{
asdf:string;
qwer : number;
}>
type Defaults = Required<{
asdf: 'default';
qwer: 1234;
}>;
@colinhacks
colinhacks / gist:4c846b9b07325c600fe4c1cc38ddd5d7
Last active September 11, 2020 23:25
optional_ctx_resolver.ts
type GlobalCtx = {
session: {
authorize(): void;
};
};
type LoginInputType = {
email: string;
};
@colinhacks
colinhacks / ground_truthiness.md
Created July 31, 2020 23:55
Ground truthiness

Achieving the Holy Grail of TypeScript Data Modeling Or, a scalable solution to type complexity

For the highly abbreviated version of this, check out this comment: colinhacks/zod#53 (comment). That comment conveys why this is so exciting. If you agree then the outline below explains the context for why I think it’s so exciting and introduces a the architectural concept of “ground truthiness” which I think is a very powerful notion.

Context

This journey started in 2018 when I decided to start a company. For inexplicable reasons I decided to build an electronic medical record software, one of the most regulated and complex product categories in the world. Also I was a solo founder. Now if you’re ever tempted to do this, for the love of god, don’t. Just say no!

Since this was medical software so I wanted it to be rock solid — end to end typesafety, powerful and expressive endpoints, painless schema migration. I was deeply entrenched in vanilla JavaScript development,