Skip to content

Instantly share code, notes, and snippets.

View mvhenten's full-sized avatar
💭
I may be slow to respond.

Matthijs van Henten mvhenten

💭
I may be slow to respond.
  • Amsterdam, The Netherlands
View GitHub Profile

Run openvscode-server from Podman

1. Install podman.

apt-get install -y podman

2. Configure some container registries

@mvhenten
mvhenten / action.yaml
Last active January 21, 2025 14:39
Setup code-artifact for github actions
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
@mvhenten
mvhenten / generate-module-d.mjs
Created December 5, 2024 11:32
Generate a module.d.ts types from the config file using json-ts.
#!/usr/bin/env node
/**
* Generate a module.d.ts types from the config file using json-ts.
*
* Using a rollup plugin to generate a "virtual:config" we now have
* access to type-safe runtime configuration:
*
* import { config } from "config";
*/
@mvhenten
mvhenten / currencies.mjs
Last active July 11, 2024 08:27
Create CountryCode and CurrencyCode enums for typespec
import Papa from "papaparse";
import fs from "node:fs";
const currencies = () => {
const data = fs.readFileSync("./currency.csv").toString();
const result = Papa.parse(data);
const currencies = Array.from(
new Set(
result.data
@mvhenten
mvhenten / schema.ts
Last active July 9, 2024 07:36
schema schema
import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb";
import {
DynamoDBDocumentClient,
QueryCommand,
GetCommand,
PutCommand,
PutCommandOutput,
} from "@aws-sdk/lib-dynamodb";
type PathToType<T> = T extends `:${infer N}`
type RequiredDefined<T extends Record<string, unknown>> = {
[key in keyof T]-?:NonNullable<T[key]>
}
export function assertOptions<Options extends Record<string, unknown>, Keys extends keyof Options, Result extends Pick<Options, Keys>>(options:Options, ...keys:Keys[]):RequiredDefined<Result> {
const result = {} as Record<string, unknown>
for (let key of keys as string[]) {
if (options[key] === undefined) {
throw new TypeError(`Expected ${String(key)} to be defined`);
@mvhenten
mvhenten / use-validate.ts
Last active March 5, 2023 13:58
Utility hook that helps with: https://cloudscape.design/patterns/general/validation/ "Validate the data after a user submits a form for the first time. Don’t validate before the user submits the form for the first time. On subsequent attempts, validate as the user completes each field."
import { useState } from "react";
type ValidationValues = Record<string, unknown>;
type ValidationFunction<T> = (v: T) => string | void;
export type ValidationErrors = Record<string, string[]>;
function runValidation(
key: string,
validators: ValidationFunction<unknown>[],
@mvhenten
mvhenten / gif.sh
Last active March 26, 2025 10:07
creat a gif from screen recording
INPUT_FILE=yourfilehiere.mov
OUTPUT_FILE=outputname.gif
ffmpeg -i $INPUT_FILE -vf "fps=16,scale=960:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=32:reserve_transparent=0[p];[s1][p]paletteuse" $OUTPUT_FILE
import { suite, test, TestContext } from "./mtap";
suite("test label", ({ test }) => {
test("another test", (t:TestContext) => {
t.assert("OK computer");
t.assert(false, "intentionally failed");
});
test("hula hoop", (t:TestContext) => {
t.assert(true, "juhu");
import { set, get, createStore, UseStore, values, clear } from 'idb-keyval';
export abstract class Ministor<ItemType> {
private db: UseStore;
constructor() {
const ns = this.constructor.name;
this.db = createStore(ns, [ns, "items"].join(":"));
}