Skip to content

Instantly share code, notes, and snippets.

View esamattis's full-sized avatar

Esa-Matti Suuronen esamattis

View GitHub Profile
@esamattis
esamattis / launch.json
Last active April 11, 2024 07:06
Debug jest tests in vscode with pnpm
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"runtimeExecutable": "sh", // <-- The important bit!
"program": "node_modules/.bin/jest",
"args": ["${relativeFile}"],
@esamattis
esamattis / utils.tsx
Created September 17, 2018 19:01
Typescript DeepRequired
type NotNill<T> = T extends null | undefined ? never : T;
type Primitive = undefined | null | boolean | string | number | Function;
type DeepRequired<T> = T extends Primitive
? NotNill<T>
: {
[P in keyof T]-?: T[P] extends Array<infer U>
? Array<DeepRequired<U>>
: T[P] extends ReadonlyArray<infer U2>
@esamattis
esamattis / Dockerfile
Last active December 21, 2023 20:21
How to deploy a single app to a container from a pnpm monorepo using `pnpm deploy` in Github Actions
FROM node:14-slim
ENV NODE_ENV=production
COPY pnpm-deploy-output /app
WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]
$ cat Cargo.toml
[package]
name = "rustdepstest"
version = "0.1.0"
edition = "2021"
[dependencies]
swc = "0.264.38"
$ cargo tree
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("")
base = alphabet.length
exports.encode = (i) ->
return alphabet[0] if i is 0
s = ""
while i > 0
s += alphabet[i % base]
i = parseInt(i / base, 10)
@esamattis
esamattis / ColdWater
Last active February 9, 2023 11:31
Reading Hydrodigit-S1 water meter with iM871A-USB and wmbusmeters to Home Asisstant sensor
# /etc/wmbusmeters.d/ColdWater
name=ColdWater
# the id printed on the meter
id=030xxxxx
key=NOKEY
driver=hydrodigit
@esamattis
esamattis / trpc-test-link.ts
Last active January 12, 2023 08:45
tRPC local / test link for testing
@esamattis
esamattis / typed-loaders.ts
Created May 19, 2022 20:59
TypeScript inference for Remix.run loaders and actions
import { json } from "@remix-run/node";
import { useActionData, useLoaderData } from "@remix-run/react";
export function useTypedLoaderData<T extends (arg: any) => any>(): Awaited<
ReturnType<T>
> {
return useLoaderData();
}
export function useTypedActionData<T extends (arg: any) => any>():
@esamattis
esamattis / scroll-into-view.ts
Created August 24, 2022 21:59
scrollIntoViewIfNeeded() that works with `overflow: scroll` parent divs etc. as well
function getScrollContainer(node: HTMLElement | null): HTMLElement | null {
if (!node) {
return null;
}
if (node.scrollHeight > node.clientHeight) {
if (node === document.body) {
return document.documentElement;
}
return node;
#!/bin/sh
mountroot_fail()
{
if [ -x /sbin/lvm ]; then
echo "Trying to fix lvm"
set -x
/sbin/lvm vgscan
/sbin/lvm vgchange -a y --sysinit