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 interface IParallelJobQueue<T> { | |
| add(fn: AsyncFunction<T>, ...args: any[]): void; | |
| process(): Promise<void>; | |
| results(): { | |
| succesfulResults: T[], | |
| failedResults: T[] | |
| }; | |
| progress(): number; | |
| } | |
| type AsyncFunction<T> = (...args: any[]) => Promise<T>; |
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 class CancellationToken { | |
| #isCancellationRequested: boolean = false; | |
| get isCancellationRequested() { | |
| return this.#isCancellationRequested; | |
| } | |
| cancel() { | |
| this.#isCancellationRequested = 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
| export const shuffleArray = arr => arr.sort(() => Math.random() - 0.5); | |
| export const isPalindrome = str => str === str.split('').reverse().join(''); | |
| export const isEmailValid = email => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); | |
| export const generateUUID = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => (Math.random() * 16 | 0).toString(16)); | |
| export const calculateDistance = (lat1, lon1, lat2, lon2) => { const rad = x => x * Math.PI / 180; const R = 6371; const dLat = rad(lat2 - lat1); const dLon = rad(lon2 - lon1); return R * 2 * Math.asin(Math.sqrt(Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(rad(lat1)) * Math.cos(rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/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
| import { logger } from './logger'; | |
| import { isFunction } from 'lodash'; | |
| export function trace( | |
| target: any, | |
| propName?: string, | |
| propDescriptor?: PropertyDescriptor | |
| ) { | |
| if (propDescriptor) { | |
| // Decorating a Method |
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 -x | |
| # Ensure script stops when commands fail. | |
| set -e | |
| # Backup & compress our database to the temp directory. | |
| sqlite3 /path/to/db '.backup /tmp/db' | |
| gzip /tmp/db | |
| # Upload backup to S3 using a rolling daily naming scheme. |
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
| taskkill /im explorer.exe /f | |
| start explorer.exe | |
| exit |
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 Flatten<T> = T extends object ? { | |
| [P in keyof T]: Flatten<T[P]> | |
| } : T; | |
| type A = { foo: boolean } & { bar: string }; | |
| type B = Flatten<A>; // { foo: boolean; bar: 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
| { | |
| "version": "2", | |
| "templates": [ | |
| { | |
| "type": 1, | |
| "title": "Registry", | |
| "description": "Docker image registry", | |
| "categories": [ | |
| "docker" | |
| ], |
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 { Request, Response, NextFunction } from 'express'; | |
| import { environment } from '../environment'; | |
| // This functions prints Request and Response data on graphql endpoint | |
| export function loggerMiddleware( | |
| req: Request, | |
| res: Response, | |
| next: NextFunction | |
| ) { | |
| if (!environment.loggerMiddleware) { |
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
| exports.errorHandler = (response, err) => { | |
| const statusCode = err.status || 500; | |
| response.status(statusCode).json({ | |
| success: false, | |
| error: err.message | |
| }); | |
| }; | |
| exports.successHandler = (response, data) => { | |
| response.json({ |
NewerOlder