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
// performs a circular shift on an array (i < 0 ? right : left) | |
Object.defineProperty(Array.prototype, 'rotate', { | |
enumerable: false, | |
value: function (i) { | |
if (i == 0) return this; | |
const s = (this.splice).apply(this, i < 0 ? [i] : [0, i]); | |
(i < 0 ? this.unshift : this.push).apply(this, s); | |
return this; | |
} | |
}); |
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 Deferred() { | |
this.promise = new Promise((resolve, reject) => { | |
this.resolve = resolve; | |
this.reject = reject; | |
}) | |
} |
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
// usage: promisify(instance.func.bind(instance)) | |
function promisify(fun) { | |
return function (...args) { | |
return new Promise((resolve, reject) => { | |
fun.apply(fun, [].concat(args, (err, res) => (err) ? reject(err) : resolve(res))) | |
}) | |
} | |
} |
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 assert = require('assert'); | |
function makeTypedError(args) { | |
assert(args, 'TypedError: must specify options'); | |
assert(args.type, 'TypedError: must specify options.type'); | |
assert(args.message, 'TypedError: must specify options.message'); | |
assert(args.statusCode, 'TypedError: must specify options.statusCode'); | |
return (class extends Error { | |
constructor(message) { |
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 http = require('http'); | |
const tls = require('tls'); | |
const url = require('url'); | |
const getSslDetails = (host) => new Promise((resolve, reject) => { | |
const sock = tls.connect({rejectUnauthorized: false, port: 443, host}, () => { | |
const certs = sock.getPeerCertificate(); | |
delete certs.raw; | |
resolve({ | |
authorized: sock.authorized, |
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
/** | |
* @description exec "fun" with each "arr" element, one after the other | |
* @template T, S | |
* @param {Array.<T>} arr | |
* @param {function(T): S} fun | |
* @returns Promise.<S> | |
*/ | |
const promiseChain = (arr, fun) => arr.reduce((p, e) => p.then(() => fun(e)), Promise.resolve()); |
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 net = require('net'); | |
const isServer = process.argv[2] == 'server'; | |
const port = process.argv[3]; // server port | |
const display = (data) => console.log('> ' + data.toString().trim()); | |
let send = null; | |
if (isServer) { |
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/sh | |
VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[", ]//g') | |
echo "Version is >${VERSION}<" |
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
location /__special { | |
internal; | |
allow all; | |
root /usr/share/nginx/html/__special; | |
} | |
location = /__md_file { | |
internal; | |
allow all; |
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
# autocompletion for d and dokcer (docker) | |
source /usr/share/bash-completion/completions/docker | |
complete -F _docker d dokcer |
OlderNewer