Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / binom-test.js
Last active July 2, 2021 07:51
[javascript] [statistics](both welch's and student's) t-test implementations
/*
// binomial coefficient nCk
function binom(n, k) {
k = n - k < k ? n - k : k;
const b = [1].concat(Array.from(Array(k), _ => 0));
for (let i = 1; i <= n; i++) {
for (let j = i < k ? i : k; j > 0; j--) b[j] += b[j - 1];
}
return b[k];
}
@ahtcx
ahtcx / deep-merge.js
Last active June 9, 2024 14:56
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}
@kfox
kfox / tcpproxy.js
Created April 5, 2012 20:03
A basic TCP proxy written in node.js
var net = require("net");
process.on("uncaughtException", function(error) {
console.error(error);
});
if (process.argv.length != 5) {
console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]);
process.exit();
}