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
const apiUrl = 'https://jsonplaceholder.typicode.com'; | |
const createUserEndpoint = userId => apiUrl + '/users/' + userId; | |
const createTodosEndpoint = userId => createUserEndpoint(userId) + '/todos'; | |
const createAltTodosEndpoint = userId => apiUrl + '/todos?userId=' + userId; | |
const createTimeout = seconds => new Promise( | |
(_, reject) => setTimeout(() => reject('TIMEOUT'), seconds * 1000) | |
); | |
const fetchJSON = endpoint => fetch(endpoint).then(res => res.json()); | |
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
let maxSafeInteger = 2 ** 53 - 1; | |
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991 | |
console.log(maxSafeInteger); // 9007199254740991 | |
console.log(maxSafeInteger + 1); // 9007199254740992 | |
console.log(maxSafeInteger + 2); // 9007199254740992 😯 | |
let bigInteger = 2n ** 53n - 1n; | |
maxSafeInteger = BigInt(Number.MAX_SAFE_INTEGER); |
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
const log = console.log; | |
/* #1 Array.prototype.fill [0.7s/10M ops] */ | |
log(Array(10).fill(0).map((_, i) => i)); | |
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
/* #2 Array.apply & Array.prototype.map [1.9s/10M ops] */ | |
log(Array.apply(null, Array(10)).map((_, i) => i)); | |
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
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 Repeat<T, Count, Acc extends any[] = []> = Acc['length'] extends Count ? Acc : Repeat<T, Count, [...Acc, T]>; | |
function i18n<Keys extends number[]>([result, ...parts]: TemplateStringsArray, ...keys: Keys) { | |
return (...param: Repeat<string, Keys['length']>) => | |
keys.reduce((acc, key, i) => acc + (param as number[])[key] + parts[i], result); | |
} | |
const introduceEn = i18n`Hi. My name is ${0}. I work as a ${1} at ${2}.`; | |
const introduceTr = i18n`Merhaba. Benim adım ${0}. ${2} şirketinde ${1} olarak çalışıyorum.`; | |
// (param_0: string, param_1: string, param_2: string) => string |
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 Strict<Contract, Class> = Class extends Contract | |
? { [K in keyof Class]: K extends keyof Contract ? Contract[K] : never } | |
: Contract; | |
interface MyContract { | |
foo: number; | |
bar: boolean; | |
} | |
type MyStrictContract = Strict<MyContract, MyClass>; |
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
const diacriticsMap = { | |
a: 'a', | |
A: 'A', | |
ₐ: 'a', | |
á: 'a', | |
Á: 'A', | |
à: 'a', | |
À: 'A', | |
ă: 'a', | |
Ă: 'A', |
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
// http-errors.js | |
export class HttpError extends Error { | |
code; | |
url; | |
constructor(code, url, message) { | |
super(message); | |
this.code = code; | |
this.url = url; | |
} |
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
# rest of your Zsh configuration here | |
demo () { | |
if [ ! "$#" -gt 0 ]; then echo "Missing application name!"; return 1; fi | |
case "$2" in | |
"") | |
mkdir $1; | |
cd $1; | |
npm init -y; | |
;; |
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
import { Component, Inject, InjectionToken, NgModule } from "@angular/core"; | |
import { RouterModule } from "@angular/router"; | |
export const FOO = new InjectionToken<string>("FOO"); | |
@Component({ | |
selector: "app-foo", | |
template: "{{ foo }} works!" | |
}) | |
export class FooComponent { |
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
import { Component, NgModule } from "@angular/core"; | |
import { BrowserModule } from "@angular/platform-browser"; | |
import { RouterModule } from "@angular/router"; | |
import { FooModule } from "./foo.module"; | |
@Component({ | |
selector: "app-root", | |
template: "<router-outlet></router-outlet>" | |
}) | |
export class AppComponent {} |