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 arr = [ { prop: [1,2,3] }, { prop: [3,4,5] } ]; | |
| * let result = concatBy(arr, 'prop'); | |
| */ | |
| const concatBy = <T>(arr: T[], propName: string): T[] => | |
| arr.reduce((acc: T[], val) => acc.concat(val[propName]), []); | |
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
| export type ResultAndError<T, E extends Error> = [T | null, E | null]; // tuple | |
| export const to = <T>(promise: Promise<T>): Promise<ResultAndError<T, Error>> => { | |
| return promise.then<ResultAndError<T, Error>>(data => { | |
| return [data, null]; | |
| }) | |
| .catch<ResultAndError<T, Error>>(err => [null, err]); | |
| }; | |
| const [result, error] = await to(this.anything.promising()); |
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
| cat ~/.ssh/ngrnv_rsa.pub | ssh user@server "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys” |
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
| export const log = <T>(tag: string = '') => tap<T>( | |
| next => console.log(`%c[${tag}: Next]`, 'color: #4CAF50;', next), | |
| error => console.log(`%c${tag}: Error]`, 'color: #F44336;', error), | |
| () => console.log(`%c[${tag}: Complete]`, 'color: #2196F3;') | |
| ); | |
| /* | |
| usage: | |
| ... | |
| .pipe( |
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
| ssh-keygen -t rsa -b 4096 -m PEM -f fg-platform-auth.key | |
| # Don't add passphrase | |
| openssl rsa -in fg-platform-auth.key -pubout -outform PEM -out fg-platform-auth.key.pub | |
| cat fg-platform-auth.key | |
| cat fg-platform-auth.key.pub |
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
| /** | |
| * Triggered on (change) event on checkbox inside template form | |
| * See https://github.com/ng-bootstrap/ng-bootstrap/issues/1252 | |
| */ | |
| onChange(event: Event) { | |
| /* The Angular form directives have bindings that update synchronously based on focus change | |
| The modal brings focus to the window (required by accessibility) */ | |
| (event.target as HTMLInputElement).blur(); |
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
| module.exports = Deferred | |
| Deferred.defer = defer | |
| function Deferred(Promise) { | |
| if (Promise == null) Promise = global.Promise | |
| if (this instanceof Deferred) return defer(Promise, this) | |
| else return defer(Promise, Object.create(Deferred.prototype)) | |
| } | |
| function defer(Promise, deferred) { |
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 * as React from 'react' | |
| type ResultBox<T> = { v: T } | |
| export default function useConstant<T>(fn: () => T): T { | |
| const ref = React.useRef<ResultBox<T>>() | |
| if (!ref.current) { | |
| ref.current = { v: fn() } | |
| } |
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
| function curry(fn) { | |
| return function curried() { | |
| return arguments.length >= fn.length | |
| ? fn.apply(null, arguments) // if there are all args - execute fn with them | |
| : curried.bind(null, ...arguments) // return new version of curried() with prepended arg(s) | |
| } | |
| } | |
| curry((x, y, z) => x + y + z)(5)(4)(1); // 10 |
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
| enum LogLevel { | |
| ERROR, WARN, INFO, DEBUG | |
| } | |
| /** | |
| * This is equivalent to: | |
| * type LogLevelStrings = 'ERROR' | 'WARN' | 'INFO' | 'DEBUG'; | |
| */ | |
| type LogLevelStrings = keyof typeof LogLevel; |
OlderNewer