Skip to content

Instantly share code, notes, and snippets.

const wrap = require('./wrapper').wrap;
function sleep(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
})
}
async function f1() {
await wrap(sleep(1), __filename, 9);
throw new Error('error1');
const fs = require('fs');
const fsp = require('path');
function scan(dir, results, mod) {
fs.readdirSync(dir).forEach(name => {
const path = fsp.join(dir, name);
let m;
if (fs.statSync(path).isDirectory()) {
scan(path, results, name === 'node_modules' ? null : mod === null ? name : mod);
} else if (mod && (m = /(.*)\.[jt]s$/.exec(name)) && !/\.(d|min|debug)$/.test(m[1])) {
"use strict";
// experimental value
// nsyms is size of alphabet (62 for letters + digits)
// len is password length
// maxReapeat is the max number of repeats we allow
// returns the probability of a password reject.
function expe(nsyms, len, maxRepeat) {
// generate random array of len symbols
const gen = len => {
var Fiber = require('fibers');
function sleep(millis, id) {
var fiber = Fiber.current;
console.log(id + ": sleep begin");
setTimeout(function() {
console.log("wake up");
fiber.run();
}, millis)
Fiber.yield();
var Fiber = require('fibers');
function sleep(millis, id) {
var fiber = Fiber.current;
console.log(id + ": sleep begin");
setTimeout(function() {
console.log("wake up");
fiber.run();
}, millis)
Fiber.yield();
console.log("script begin");
var Fiber = require('fibers');
Fiber(function() {
var fiber = Fiber.current;
setTimeout(function() {
console.log("setTimeout callback begin");
fiber.run();
console.log("setTimeout callback end");
}, 10000)
"use strict";
class Complex {
constructor(a, b) {
this.re = a;
this.im = b;
}
add(c) {
return new Complex(this.re + c.re, this.im + c.im);
}
"use strict";
function assert(i, j) {
if (i !== j) throw new Error("expected " + i + ", got " + j)
}
function callbackIter(fn, n, cb) {
var t0 = Date.now();
(function doIt(i) {
if (i < n) fn(i, function(err, val) {
var oracledb = require('oracledb');
var ez = require('ez-streams');
var cnx = oracledb.getConnection({
user: "scott",
password: "oracle",
connectString: "localhost/ORCL",
}, _);
try {
"use strict";
exports.queryAll = function(conn, sql, args, cb) {
var allRows = [];
conn.execute(sql, args, {
resultSet: true
}, function(err, result) {
if (err) return cb(err);
function fetch() {