This file contains 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
const subscriptNumber = (n) => n | |
.toString(10) | |
.split`` | |
.map((i) => Number.parseInt(i, 10)) | |
.map((i) => String.fromCharCode(0x2080 + i)) | |
.join`` | |
const countBadges = (badges) => Array | |
.from( | |
[...new Intl.Segmenter().segment(badges)] |
This file contains 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
const uuid7Re = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | |
const parseUuid7Date = (uuid) => { | |
if (typeof uuid !== `string` || !uuid7Re.test(uuid)) { | |
throw new TypeError(`Expected UUIDv7. Received: ${String(uuid)} (${typeof uuid})`) | |
} | |
const timestampHex = uuid.slice(0, 13).replace(`-`, ``) | |
const timestamp = Number.parseInt(timestampHex, 16) | |
return new Date(timestamp) |
This file contains 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
const uuid4to7 = (uuid, now = Date.now()) => { | |
const ts = now.toString(16).padStart(12, `0`) | |
return `${ts.slice(0, 8)}-${ts.slice(8)}-7${uuid.slice(15)}` | |
} | |
// generate new UUIDv7 | |
uuid4to7(crypto.randomUUID()) | |
// Conforms to example in the spec RFC9562 A.6 |
This file contains 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
/* | |
============================= | |
Railway Oriented Typescript | |
============================= | |
by @robinpokorny | |
*/ | |
/* === 1. Union basics === */ | |
const a: string | number = 42; |
This file contains 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 | |
# Mirrors all GitHub repositories the current user has read access to. | |
# See license at the end of the file. | |
# Token from https://github.com/settings/tokens | |
OAUTH_TOKEN="<TODO TOKEN>" | |
# where should the files be saved | |
DIR="<TODO PATH>" |
This file contains 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
/* | |
============================= | |
Railway Oriented Typescript | |
============================= | |
by @robinpokorny | |
*/ | |
/* === 1. Union basics === */ | |
const a: string | number = 42; |
This file contains 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
// And you will know my name is TypeScript | |
// When I lay my Tagged Union upon thee | |
// by @robinpokorny | |
// 1. Union of literals | |
// The cornerstone of any nutritious breakfast. | |
type Burger1 = `McDonalds` | `BigKahuna`; | |
const brettsBreakfast1_1: Burger1 = `BigKahuna`; | |
const brettsBreakfast1_2: Burger1 = `Whooper`; // Caught |
This file contains 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
const sum = (a, b) => a + b | |
const getMostProfitFromStockQuotes = (quotes, current = 0) => { | |
if (quotes.length < 2) return current | |
const max = Math.max(...quotes) | |
const maxAt = quotes.indexOf(max) | |
const left = quotes.slice(0, maxAt) |
This file contains 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
export const enum InformationalResponse { | |
Continue = 100, | |
SwitchingProtocols = 101, | |
Processing = 102, | |
EarlyHints = 103, | |
} | |
export const enum Success { | |
OK = 200, | |
Created = 201, |
This file contains 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
const words = ["hello", " ", "world"]; | |
for (let i = 0; i <= words.length; i++) { | |
const word = words[i]; | |
if (word.length <= 0) continue; | |
words[i] = uppercaseFirstLetter(word.trim()); | |
} | |
const titlecasedWords = words | |
.filter(isNotEmpty) |
NewerOlder