Skip to content

Instantly share code, notes, and snippets.

@chad3814
chad3814 / listener-pipe.mjs
Last active March 14, 2022 19:29
example node 16 short body closed socket bug
import fs from 'fs';
import http from 'http';
import stream from 'stream';
class CountingStream extends stream.PassThrough {
constructor(options) {
super(options);
this._bytes_in = 0;
this._bytes_out = 0;
}
@chad3814
chad3814 / StatesColoring.js
Last active August 13, 2018 21:29
States coloring problem
'use strict';
class Color {
constructor (name, multiplier) {
this.name = name;
this.multiplier = multiplier;
}
}
let colors = [
@chad3814
chad3814 / binding.gyp
Created June 19, 2018 00:54
async worker/emitter example
{
"targets": [
{
"target_name": "AsyncEmitter",
"sources": [ "emitter.cc" ],
"include_dirs": [],
"dependencies": [],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],

Keybase proof

I hereby claim:

  • I am chad3814 on github.
  • I am chad3814 (https://keybase.io/chad3814) on keybase.
  • I have a public key ASCCzcAKbW362pseb1Cjk3ZscwaGyBPJPwXemS2N-NN7gQo

To claim this, I am signing this object:

var key_file = fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'non_ev_domains.key'));
var cert_file = fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'non_ev_domains.crt'));
var ca_files = [
fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'COMODORSADomainValidationSecureServerCA.crt')),
fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'COMODORSAAddTrustCA.crt'))
];
var credentials = {
key: key_file,
cert: cert_file,
ca: ca_files

Keybase proof

I hereby claim:

  • I am chad3814 on github.
  • I am chad3814 (https://keybase.io/chad3814) on keybase.
  • I have a public key whose fingerprint is FEC7 4FF5 182D B552 4729 D20D 7886 F7FB F31A D420

To claim this, I am signing this object:

@chad3814
chad3814 / bools.js
Last active October 22, 2021 20:15 — forked from sjl/list-out-of-lambda.js
fixed jslint errors, spacing a bit
'use strict';
var not = function (x) {
if (x) {
return false;
}
return true;
};
var and = function (a, b) {
@chad3814
chad3814 / van.js
Created March 18, 2013 23:36
make a directory, put this file in it, npm install socket.io, node van.js
'use strict';
var http = require('http');
var sio = require('socket.io');
var app = http.createServer(function (req, res) {
if (req.url === '/') {
res.writeHead(200, {
'Content-Type': 'text/html'
});
@chad3814
chad3814 / foo.js
Last active November 23, 2021 03:31
waiting for content to be loaded in jsdom
'use strict';
var path = require('path');
var jsdom = require('jsdom');
var dumpBody = function (document) {
console.log('contents of the document:');
console.log(document.body.innerHTML);
};
@chad3814
chad3814 / gist:2924672
Last active January 16, 2024 20:27
deleting array items in javascript with forEach() and splice()
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561
/*
* How to delete items from an Array in JavaScript, an exhaustive guide
*/
// DON'T use the delete operator, it leaves a hole in the array:
var arr = [4, 5, 6];
delete arr[1]; // arr now: [4, undefined, 6]