Skip to content

Instantly share code, notes, and snippets.

@matthewsimo
matthewsimo / jest-to-vitest.sh
Created April 26, 2024 14:08 — forked from wojtekmaj/jest-to-vitest.sh
Automatically migrate Jest project to Vitest
#!/bin/bash
# Ensure we're working on the latest version of the main branch
git switch main
git fetch
git pull
# Create a new branch
git switch -c vitest
@matthewsimo
matthewsimo / optional-type.ts
Created September 28, 2023 21:05
Optional Type Util TS
export type Optional<T, U extends keyof T> = Partial<Pick<T, U>> & Omit<T, U>;
@matthewsimo
matthewsimo / get-css-custom-properties.js
Created July 28, 2023 22:10
Get all CSS Custom Properties for root
let vars = new Map()
for (const [prop, val] of document.documentElement.computedStyleMap()) {
if (prop.startsWith('--')) {
vars.set(prop, val[0][0])
}
}
for (const [k, v] of vars.entries()) {
console.log(`${k}: ${v}`)
}
@matthewsimo
matthewsimo / get_input.sh
Created December 9, 2022 22:03
Download the aoc input for a day
#!/bin/bash
# example usage: `$ ./get_input.sh 09`
echo "getting input file for day ${1}";
PATH="input/${1}.txt";
YEAR="2022";
DAY=$(echo "${1}" | /usr/bin/sed 's/^0*//');
URL="https://adventofcode.com/${YEAR}/day/${DAY}/input";
@matthewsimo
matthewsimo / benchmarks.txt
Last active July 22, 2022 16:01
npm vs bun vs pnpm
npm:
No package-lock.json, no node_modules:
(higher variance so I included multiple)
real 1m32.585s
user 1m9.851s
sys 0m38.996s
@matthewsimo
matthewsimo / main.js
Last active June 22, 2022 22:04
Save video & screenshot for page with playwright
const { chromium } = require("playwright"); // Or 'chromium' or 'firefox'.
(async () => {
const browser = await chromium.launch({
channel: "chrome-canary",
args: ["--enable-unsafe-webgpu"],
headless: false,
});
const context = await browser.newContext({
@matthewsimo
matthewsimo / type-utils.ts
Last active May 4, 2022 21:14
Typescript Type Utils
export type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
// expands object types recursively
export type ExpandRecursively<T> = T extends object
? T extends infer O
? { [K in keyof O]: ExpandRecursively<O[K]> }
: never
: T;
@matthewsimo
matthewsimo / ExampleUsage.tsx
Last active September 9, 2023 14:01
Help Storybook properly handle the relevant Stitches variants & props
import type * as Stitches from "@stitches/react";
import { modifyVariantsForStory } from "../../../.storybook/type-utils";
import { styled } from "../../stitches.config";
const Example = styles("div", {
// ...
});
export default Example;
// Fetch the book data
var books = fetch('http://someaweomseapi.com/api')
.then(function(response){
return response.json();
})
.then(function(json){
console.log('fetch result:', json)
return json
})