This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/public/bin/perl -w | |
| use strict; | |
| use JSON; | |
| use JSON::WebToken; | |
| use LWP::UserAgent; | |
| use HTML::Entities; | |
| my $private_key_string = q[-----BEGIN PRIVATE KEY----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /****************************************************************************** | |
| * Implementation of `Nonempty` validator which checks that the provided type | |
| * has at least one defined property, excluding `{}`. | |
| ******************************************************************************/ | |
| type Nonempty<T extends { [key: string]: any }> = { [P in keyof T]: T }[keyof T]; | |
| declare function wantsNonempty<T extends { [key: string]: any }>(x: Nonempty<T>): true; | |
| wantsNonempty({ x: 1 }); | |
| wantsNonempty({}); // error expected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/gpp | |
| #mode comment "/*" "*/" | |
| /******************************************************************************/ | |
| /* ALL CODE GENERATED BY THIS FILE SHOULD RETAIN COMMENTS, NOTES, AND */ | |
| /* FORMATTING SO THAT IN THE FUTURE IF THE PREPROCESSOR IS LOST, THE CODE IS */ | |
| /* PRESERVED. */ | |
| /******************************************************************************/ | |
| #mode string QQQ "<<EOL\n" "\nEOL" | |
| #define e(str) str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ################################################################################ | |
| # Introduction | |
| ################################################################################ | |
| # This is an attempt at explaining how to vendor git repositories by storing | |
| # their _entire_ commit history inside of the local repository. By vendoring | |
| # dependencies using this technique, the remote repository can entirely | |
| # recreated from the local repository if the original were to be lost. | |
| # Additionally, clones of the local repository also satisfy that property. | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Stump<N extends number, U extends readonly unknown[] = [], V extends readonly unknown[] = []> = N extends N ? number extends N ? readonly unknown[] : U["length"] extends N ? V : Stump<N, readonly [unknown, ...U], [unknown?, ...V]> : never; | |
| type Truncate<T extends readonly unknown[]> = T extends [unknown?, ...infer U] ? T extends [...infer X, ...U] ? X : never : never; | |
| type Select<T extends readonly unknown[], I extends keyof T & number> = Truncate<T extends readonly [...Stump<I>, ...infer U] ? U : []>; | |
| type a = Select<[1,2,3], 1> // [2] | |
| type b = Select<number[], 1> // [number?] // still doesn't work | |
| type c = Select<[1,2?,3?], 1> // [2?] | |
| type d = Select<[ foo: 1, bar?: 2 ], 1> // [ bar?: 2 ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Type alias resolves to `True` if and only if `U` is the same as `V`, otherwise it resolves to `False`. | |
| * @typeparam U - An arbitrary type | |
| * @typeparam V - An arbitrary type | |
| * @typeparam True - Production when `U` is the same as `V` | |
| * @typeparam False - Production when `U` is not the same as `V` | |
| */ | |
| export type Exact<U, V, True = true, False = false> = | |
| { <_>(): _ extends U ? 1 : 0 } extends { <_>(): _ extends V ? 1 : 0 } | |
| ? True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Get the union of all prefixes of some tuple. Finite, optional, and variadic tuples are | |
| * all supported. Labels are only preserved for finite tuples without optional members. | |
| */ | |
| type Prefixes<T extends readonly unknown[]> = | |
| T extends { length: infer X } & { length: infer Y } | |
| ? (X extends unknown ? Y extends X ? 0 : 1 : never) extends 0 | |
| ? number extends T["length"] // If the tuple is variadic | |
| ? PrefixesNoLabels<T> // we bail out and use the variadic supporting type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // [...Array(101)] : is the shortest way to generate a range from [0..100] | |
| // .map((_,n)=> : The array is filled with undefined, so we use the index instead. | |
| // "Fizz".slice(n%3&&4): (n%3) is truth-y for all non-multiples of 3. (n%3)&&4 is either 0 or 4. | |
| // ||n : "Fizz".slice(4)+"Buzz".slice(4) is "", which is false-y, so we replace it with n | |
| // .find : .map returns an array, .find does not. | |
| [...Array(101)].map((_,n)=>"Fizz".slice(n%3&&4)+"Buzz".slice(n%5&&4)||n).find(s=>console.log(s)) | |
| // An interesting, but longer variation: | |
| // n%3&&1-n%5&&4 : returns either 4 for Buzz or 0 for Fizz and FizzBuzz. (other values are excluded by the length arg) | |
| // (!(n%3)+!(n%5))*4 : returns 0, 4, or 8 for none, Fizz or Buzz, or FizzBuzz respectively. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S nginx -e /dev/stderr -p . -c | |
| # Run an NGINX instance serving the current directory on ports 8080 and 8443 | |
| # (when configured). Execute one of the following commands in the terminal. | |
| # - start-nodaemon: ./nginx.conf -g 'daemon off;' | |
| # - start: ./nginx.conf | |
| # - stop: ./nginx.conf -s stop | |
| # - reload: ./nginx.conf -s reload | |
| pid .nginx/nginx.pid; | |
| events {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // See also https://gist.github.com/webstrand/bac2bc752e3f6b22892a155ed1efa536 for definition of Prefixes<T> | |
| /** | |
| * Get the union of all prefixes of some tuple. Finite, optional, and variadic tuples are | |
| * all supported. Labels are only preserved for finite tuples without optional members. | |
| */ | |
| type Prefixes<T extends readonly unknown[]> = | |
| T extends { length: infer X } & { length: infer Y } | |
| ? (X extends unknown ? Y extends X ? 0 : 1 : never) extends 0 | |
| ? number extends T["length"] // If the tuple is variadic |