Skip to content

Instantly share code, notes, and snippets.

@beeplove
beeplove / server.js
Last active August 17, 2017 05:44
fork child process from master using node-cluster and let them re-spawn after a minimum interval but before a maximum interval
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
const min = 5 * 1000;
const max = 10 * 1000;
const waitBeforeKill = 2 * 1000;
cluster.on("fork", (worker) => {
console.log("worker forked: ", worker.process.pid);
@beeplove
beeplove / torn-number
Last active August 29, 2015 13:59
torn number
for (var i=Math.floor(Math.sqrt(1000)); i < Math.ceil(Math.sqrt(9999)); i++) {
var n = i * i;
a = Number(n.toString().substring(0, 2));
b = Number(n.toString().substring(2, 4));
if ((a + b) === i) {
// TODO: format number to display in two digits
console.log(a, b);
}
# Todo: time complexity of #feeds is N^2, reduce it.
def feeds
[].tap do |collection|
collect_feed_links[:feed_entries].entries.each do |entry|
collection.push(sanitize_entity_hash({}.tap do |entry_hash|
Constants::FEED_ATTR.each do |attr|
begin
(entry.respond_to?(attr) && entry.send(attr)) ? entry_hash[attr] = entry.send(attr) : ''
# Probably, can be done the same with below, depends on what santitize_entity_hash does
# entry_hash[attr] = entry.send(attr)