Skip to content

Instantly share code, notes, and snippets.

@eiriklv
eiriklv / Router.tsx
Created April 15, 2023 00:24
React router
import { History, Location } from "history";
import { MatchResult } from "path-to-regexp";
import { ReactElement, useContext, useEffect, useState } from "react";
import React from "react";
import { getPathMatch } from "./utils/routing";
export interface RouterContextInterface {
history?: History;
location?: Location;
basePath: string;

Thank you for the helpful response and pointers. I think I need to take my time to sort this out, thanks a lot and I'll come back with a better understanding, hopefully!

I did my homework. Now I'm not so certain about everything, so please take this with a grain of salt.

Typescript's generic functions seem to act like they're contravariant over the type parameter's type bound. I'm not entirely sure though.

Playground Link

// Assignment succeeds with F<unknown> -> F<string>
@trevor-atlas
trevor-atlas / types.ts
Last active February 16, 2024 23:59
types
export type None = null | undefined;
export type Nullable<T> = T | None;
/** Make all of T's properties nullable*/
export type NullableOfType<T> = {
[P in keyof T]: Nullable<T[P]>;
};
/** Correct type for Object.entries(myobj) */
@jrson83
jrson83 / commit-msg.issue-id-prompt.js
Created December 29, 2022 23:47 — forked from romaricpascal/commit-msg.issue-id-prompt.js
commit-msg Git hook to ask user for an issue ID when he commits and prepend it to the original commit message
#!/usr/bin/env node
var fs = require('fs'),
util = require('util');
// Rattern to format the message with the issue ID
var MESSAGE_FORMAT = '[%s] %s';
// Git commit messages are stored in a file, passed as argument to the script
// First and second arguments will be 'node' and the name of the script
var commitFile = process.argv[2];
@vasylherman
vasylherman / install Husky zsh
Last active January 5, 2023 01:28
install Husky and commitizen in non NPM projects zsh
# how to install Husky and commitizen on non NPM projects (zsh + iTerm2)
# install Husky on each opening if folder is a git repository
echo '[ -d .git ] && npx husky install > /dev/null || true' >> ~/.zshrc
# set commitizen to intercept 'git commit -m'
mkdir -p ~/.git-templates/hooks/
echo '#!/bin/bash' > ~/.git-templates/hooks/prepare-commit-msg
echo 'exec < /dev/tty && npx cz --hook || true' >> ~/.git-templates/hooks/prepare-commit-msg
@Laurentyb
Laurentyb / prepare-commit-msg.sh
Created December 14, 2022 15:45
Git hook for preparing JIRA commit messages
#!/bin/sh
#
# git prepare-commit-msg hook for automatically prepending an issue key
# from the start of the current branch name to commit messages.
# check if commit is merge commit or a commit ammend
if [ $2 = "merge" ] || [ $2 = "commit" ]; then
exit
fi
ISSUE_KEY=`git branch | grep -o "\* \(.*/\)*[A-Z]\{2,\}-[0-9]\+" | grep -o "[A-Z]\{2,\}-[0-9]\+"`
@khalidx
khalidx / typescript-monorepo.md
Last active December 2, 2023 04:45
A simple setup for a TypeScript monorepo.

There are countless guides online for setting up a TypeScript monorepo.

Most rely on external tools like Lerna, Yarn, Turborepo, Yalc, or something else.

Here's a simple, zero-opinion way to get a TypeScript monorepo going.

First, make a structure like this:

root/
@idan
idan / router.ts
Last active May 20, 2023 18:00
basic router in typescript
export type Route = {
method: "*" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE"
path: string
regexp: RegExp
handler: (request: Request, route: MatchedRoute) => Promise<Response>
}
export type MatchedRoute = Route & {
url: URL
}
@mike-jewell
mike-jewell / index.ts
Created October 25, 2022 01:44
vite-plugin-ssr_https
import express from 'express'
import compression from 'compression'
import { renderPage } from 'vite-plugin-ssr'
import { Options } from 'sirv'
import fs from 'fs'
import path from 'path'
import https from 'https'
const isProduction = process.env.NODE_ENV === 'production'
const root = `${__dirname}/..`
@belgattitude
belgattitude / ci-pnpm-install.md
Last active April 18, 2025 13:41
Composite github action to improve CI time with pnpm

Why

Although @setup/node as a built-in cache option, it lacks an opportunity regarding cache persistence. Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

Requirements

pnpm v7 or v8 (not using pnpm ? see the corresponding yarn action gist)

Bench