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 class CancellationToken { | |
#isCancellationRequested: boolean = false; | |
get isCancellationRequested() { | |
return this.#isCancellationRequested; | |
} | |
cancel() { | |
this.#isCancellationRequested = true; | |
} | |
} |
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 -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 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 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 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 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({ |
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 function uuid() { | |
let rnd: number, val: { toString: (arg0: number) => string }; | |
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => { | |
rnd = (Math.random() * 16) | 0; | |
val = c === "x" ? rnd : (rnd & 0x3) | 0x8; | |
return val.toString(16); | |
}); | |
} |
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
(function(global){ | |
var MathUtils = { | |
powermod: function powermod(num, exp, mod){ | |
if(exp === 1) return num % mod; | |
if(exp & 1 === 1){ //odd | |
return (num * powermod(num, exp-1, mod)) % mod; | |
} | |
return Math.pow(powermod(num, exp/2, mod), 2) % mod; | |
}, |
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 | |
# Get ids of processes running longer than 6 hrs (21600 secs) | |
PIDS=$(ps eaxo etimes,bsdtime,pid,comm,cmd | grep node | grep command-line-processes | awk '{if ($1 >= 21600) print $3}') | |
for i in ${PIDS}; | |
do { | |
PROC_FILE_PATH=$(ps eaxo pid,cmd | grep node | grep "$i"| awk '{print $3}'); | |
SCRIPT_NAME=$(basename "$PROC_FILE_PATH"); | |
printf "Killing $SCRIPT_NAME\n"; |
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
module.exports = function difference(object, base) { | |
function changes(object, base) { | |
let arrayIndexCounter = 0; | |
return _.transform(object, function (result, value, key) { | |
if (!_.isEqual(value, base[key])) { | |
let resultKey = _.isArray(base) ? arrayIndexCounter++ : key; | |
result[resultKey] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value; | |
console.log("Result: " + JSON.stringify(result)); | |
} | |
}); |
NewerOlder