View selectors.js
import { createSelector } from "reselect";
const getItems = state => state.products.get("items");
export const getRenderableItems = createSelector([getItems], items => {
return items;
});
View video-stream.js
app.get('/stream', (req, res) => {
const pathToVideo = "/path/to/video";
fs.stat(pathToVideo, function(err, stats) {
if (err) {
if (err.code === 'ENOENT') {
// 404 Error if file not found
console.log('File not found!');
return res.sendStatus(404);
}
res.end(err);
View json.clj
(ns anthology.json
(:require [clojure.string :as str]))
(def escape-characters
{\return "\\r"
\newline "\\n"
\tab "\\t"
\\ "\\\\"
\" "\\\""})
View html-xml.clj
(ns anthology.xhtml
"XML/HTML emitter"
(:require [clojure.string :as str]))
(defn- yoke [& xs] (apply str (flatten xs)))
(def escape-characters
{\" """
\' "'"
\& "&"
View eventemitter.js
/*
Create an eventEmitter, which has methods "on" and "emit" with the following function signatures.
*/
var EventEmitter = {
handlers: {}, /* store a list of handler functions against each event */
/**
* @param {String} eventName
* @param {Function} callback
View bind.js
Function.prototype.bind = function() {
var args = Array.prototype.slice.call(arguments);
var context = args.shift();
var fn = this;
return function() {
fn.apply(context, args.concat(Array.prototype.slice.call(arguments)))
}
}
View exponentialBackoff.js
function exponentialBackoff(url, retries, delay, callback) {
const success = ping(url);
if (success) {
callback(result); // successfull ping
} else {
if (retries > 0) {
setTimeOut(function() {
exponentialBackoff(url, --retries, delay * 2, callback);
}, delay);
} else {
View latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms