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
//hijack.js | |
const http = require("http") | |
function hijack() { | |
override(http) | |
} | |
function requestLogger(req) { | |
const log = { | |
method: req.method || "GET", |
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* delays() { | |
let a = yield delay(800, "Hello, I'm an"); | |
console.log(a); | |
let b = yield delay(400, "async coroutine!"); | |
console.log(b); | |
} | |
const coroutine = nextValue => iterator => { | |
const { done, value } = iterator.next(nextValue); |
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 locked = 1; | |
const unlocked = 0; | |
class Mutex { | |
/** | |
* Instantiate Mutex. | |
* If opt_sab is provided, the mutex will use it as a backing array. | |
* @param {SharedArrayBuffer} opt_sab Optional SharedArrayBuffer. | |
*/ | |
constructor(opt_sab) { |
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 start = process.hrtime(); | |
const duration = process.hrtime(start); | |
const ms = (parseFloat(`${duration[0]}.${duration[1]}`) * 1000).toFixed(3); |
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
//cypress/plugins/index.js | |
let server; | |
module.exports = (on, config) => { | |
on('task', { | |
async startTestServer(data) { | |
if(server) { | |
await new Promise(resolve => server.close(resolve)); | |
} | |
const port = 3000; | |
const ip = '127.0.0.1'; |
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
loc, _ := time.LoadLocation("America/New_York") | |
longForm := "January 02 2006 03:04 pm" | |
year, month, day := time.Now().Date() | |
todayAt, err := time.ParseInLocation(longForm, fmt.Sprintf("%v %v %v %v", month, day, year, timeInput), loc) | |
if err != nil { | |
fmt.Printf("Error parsing time: %s\n", err.Error()) | |
s.User.SendString(fmt.Sprintf(timeTroubleF, timeInput)) | |
return |
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 diffSet(a, b) { | |
let x = new Set([...a].filter(n => !b.has(n))); | |
let y = new Set([...b].filter(n => !a.has(n))); | |
return new Set([...x, ...y]); | |
} |
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
/* global phantom */ | |
"use strict"; | |
var port, server, service, | |
system = require('system'); | |
if (system.args.length !== 2) { | |
console.log('Usage: phantomjs renderbuddy.js <portnumber>'); | |
phantom.exit(1); | |
} else { | |
port = system.args[1]; |
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
let defaults = { file: null }; | |
function foo(options) { | |
// Merging defaults and options objects in ES6 | |
options = [ defaults, options ].reduce(Object.assign, {}); | |
} | |
foo({ file: "happy.md" }); |
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
// jest-babel.js | |
// | |
// usage (package.json): | |
// "jest": { | |
// "scriptPreprocessor": "jest-babel.js" | |
// } | |
// | |
var path = require('path'); | |
var babel = require('babel-core'); |
NewerOlder