Skip to content

Instantly share code, notes, and snippets.

View T99's full-sized avatar
:shipit:
programmin'

Trevor Sears T99

:shipit:
programmin'
View GitHub Profile

Keybase proof

I hereby claim:

  • I am T99 on github.
  • I am t99 (https://keybase.io/t99) on keybase.
  • I have a public key whose fingerprint is DA6E E4C3 621D 5C03 BCDB 132D 7F82 5F45 2C2B CF5F

To claim this, I am signing this object:

@T99
T99 / indicies.ts
Last active February 25, 2020 21:27
TypeScript type for extracting indicies out of indexable types.
export type KnownKeys<T> = {
[K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;
export type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
type Indicies<T> = IfAny<T, string, keyof T & KnownKeys<T>>;
@T99
T99 / merged-union-type.ts
Last active February 25, 2020 18:20
A TypeScript type used to union together the keys of two or more objects.
type InternalMergedUnionType<T0 extends {}, T1 extends {}> = {
[K in keyof (T0 & T1)]: K extends keyof T0 ?
(K extends keyof T1 ?
T0[K] | T1[K] :
T0[K]) :
(K extends keyof T1 ?
T1[K] :
never);
@T99
T99 / merged-overwrite-type.ts
Last active February 25, 2020 18:36
A TypeScript type used to merge together object types and always use the property types of the last specified object type.
type InternalMergedOverwriteType<T0 extends {} = {}, T1 extends {} = {}> = {
[K in keyof (T0 & T1)]: K extends keyof T0 ?
(K extends keyof T1 ?
T1[K] : T0[K]) :
(K extends keyof T1 ?
T1[K] : never);
};
@T99
T99 / lazy-fill-image
Created June 3, 2021 14:58
Have images in HTML that lazily expand.
<div class="lazy-image" style="background: url('...')">
<canvas width="1600" height="800"></canvas>
</div>
@T99
T99 / tslint.json
Last active July 29, 2021 01:30
My 'tslint.json' Configuration
{
"extends": "tslint:recommended",
"rules": {
"adjacent-overload-signatures": false,
"align": [true,
"elements",
@T99
T99 / rfc3986.regex
Created June 22, 2021 13:08
(Mostly) RFC3986 Compliant URL/URI Parsing Regex
/(?(DEFINE)
(?<defunreserved>[A-Za-z0-9-._~])
(?<defpctencoded>\%[0-9A-Fa-f]{2})
(?<defsubdelims>[!$&'()*+,;=])
(?<defpchar>((?P>defunreserved)|(?P>defpctencoded)|(?P>defsubdelims)|:|@))
(?<defscheme>[A-Za-z][A-Za-z0-9+-.]*)
(?<defhierpart>.*?)
(?<defquery>((?P>defpchar)|\/|\?)*)
(?<deffragment>((?P>defpchar)|\/|\?)*)
)
@T99
T99 / quot.regexp
Last active July 27, 2021 12:12
Broken/Improperly-escaped quote character regex
// Matches broken 'quot' escaped strings (i.e. '&quot;' characters).
((^|[^&a-zA-Z])quot($|[^;a-zA-Z])|(^|[^&a-zA-Z])quot;|&quot($|[^;a-zA-Z]))
// Matches:
// - quot
// - quot;
// - &quot
// Does not match:
// - quote
@T99
T99 / template.service
Last active August 7, 2021 19:09
Systemd Service File Template
# Check the following link for more info:
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
[Unit]
# The descriptive text used to describe this service.
Description=description for this service
# The directory inside which this service should run.
WorkingDirectory=/home/web/web_trevorsears/@
@T99
T99 / ts-class-signature.regexp
Created August 25, 2021 20:26
TypeScript Class Signature Regexp
^\s*(?:(?<export>export)\s+)?(?<typeType>class|abstract\s+class|interface)\s+(?:(?<typeName>[a-zA-Z][a-zA-Z0-9]*)(?<typeGenerics><.*?>)?)\s+(?:extends\s+(?<extends>[a-zA-Z][a-zA-Z0-9]*(?:<.*?>)?)\s+)?(?:implements\s+(?<implements>[a-zA-Z][a-zA-Z0-9]*(?:<.*?>)?(?:,\s+[a-zA-Z][a-zA-Z0-9]*(?:<.*?>)?)*)\s+)?{