Skip to content

Instantly share code, notes, and snippets.

View forivall's full-sized avatar
🕴️
levitating

Emily Marigold Klassen forivall

🕴️
levitating
View GitHub Profile
@forivall
forivall / pre-commit
Created July 15, 2013 20:31
Don't allow git --all when files are currently staged. ~ An interesting lesson in git's use of environment vars (GIT_INDEX_FILE)
# don't allow --all when we have staged files. It's usually a mistake
# depends on procfs and won't work through gitaliases
while read -d $'\0' arg ; do
if [[ "$arg" == -a* || "$arg" == -[b-zB-Z]*a* || "$arg" == '--all' ]] ; then
if (( $((unset GIT_INDEX_FILE; git diff --cached --name-only)|wc -l) > 0 )) ; then
echo 'using --all while files are cached. don'\''t do that.'
exit 1
fi
fi
done < /proc/$PPID/cmdline
@forivall
forivall / y-combinator.ts
Last active March 27, 2024 03:38
Typescript Y-Combinator
// my brain decided to ask the question: yknow, i want you to think about the y combinator --
// like, what is it. like what the fuck girl, cmon, you have a comp sci degree, you should know this, and understand it and shit
// and so i was like fiiiiiiiiiiiiiiine gosh, lets see if typescript can handle the typing, and play around with it
// so i looked up a javascript implementation, and played with the type defintion until it
// matched up and then i was like oh: thats what the type definition of the functions in it are.
// i get it now. that's pretty cool. the main interesting thing is a the inner function that takes itself
// and returns the function initially passed to the outer function. neato.
@forivall
forivall / axios-timing.ts
Last active March 21, 2024 16:38
Axios Timing helper POC
import http = require('http')
import https = require('https')
import url = require('url')
import {AxiosInstance, AxiosInterceptorManager} from 'axios'
import {HttpRequestOptions as HttpFollowRequestOptions, http as httpFollow, https as httpsFollow} from 'follow-redirects'
import now = require('performance-now')
import httpAdapter = require('axios/lib/adapters/http')
import InterceptorManager = require('axios/lib/core/InterceptorManager')
@forivall
forivall / exclusifyUnion.ts
Last active February 23, 2024 20:27
ExclusifyUnion improved goto definiion
import { UnionToIntersection } from 'type-fest';
export type ExclusifyUnion<T> = ExclusifyUnion_<T, T>;
type ExclusifyUnion_<T, U> = T extends never
? never
: T & EmptyDifference<T, Exclude<U, T>>; // eslint-disable-line @typescript-eslint/sort-type-constituents
type EmptyDifference<T, U> = Omit<
UnionToIntersection<T extends never ? never : { [K in keyof U]?: never }>,
keyof T
>;
interface AsyncCompose {
<Options, R1, R2, R3>(
f: (options: Options) => R1,
g: (arg: Awaited<R1>, options: Options) => R2,
h: (arg: Awaited<R2>, options: Options) => R3,
): (options: Options) => R2;
<R1, R2>(f: () => R1, g: (arg: Awaited<R1>) => R2): () => R2;
<Options, R1, R2>(
f: (options: Options) => R1,
g: (arg: Awaited<R1>, options: Options) => R2,
@forivall
forivall / entry.ts
Created February 1, 2024 02:03
esm/cjs module bootstrap
async function main() {
console.log('main');
}
(async function () {
if ('undefined' !== typeof module) {
return require.main === module && main();
}
// eslint-disable-next-line no-new-func
const meta: ImportMeta = new Function('import.meta')();
@forivall
forivall / lazy.ts
Last active December 9, 2023 02:43
Fastest and smallest once wrapper in js
const unit = <T>(value: T) => () => value;
const lazy = <T>(fn: () => T) => {
let f = (): T => (f = unit(fn()))();
return () => f();
};
const lazyWithReset = <T>(fn: () => T) => {
let f: () => T;
const reset = () => {
f = () => (f = unit(fn()))();
// limit to 9 entries in the union, otherwise type instantiation gets very deep
export type ConstArrayOf<T, T2 = T> = [T] extends [never]
? []
: T extends infer U
? [U, ...ConstArrayOf<Exclude<T2, U>>]
: never;
@forivall
forivall / overrides.ts
Created November 4, 2023 02:27
override signatures
export type Overrides<T extends (...args: any) => any> = T extends {
(...args: infer A0): infer R0;
(...args: infer A1): infer R1;
(...args: infer A2): infer R2;
(...args: infer A3): infer R3;
(...args: infer A4): infer R4;
(...args: infer A5): infer R5;
(...args: infer A6): infer R6;
(...args: infer A7): infer R7;
(...args: infer A8): infer R8;
@forivall
forivall / gh-pandoc-LICENSE.md
Last active September 20, 2023 15:28
Github-style css for pandoc

The MIT License (MIT)

Copyright (c) 2016-2017 Emily M Klassen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: