Skip to content

Instantly share code, notes, and snippets.

@amalantony
amalantony / gist:30345112dad8a96b8ecd90cd8a61b292
Created November 2, 2019 16:37
Latest generated JSON and TOML
{
"components":{
"gps":{
"rule21":{
"filters":{
"message_type":"gll"
},
"outputs":{
"latitude":"data.split(\",\")[1]",
"longitude":"data.split(\",\")[2]"
{
"components":{
"gps":{
"rule2":{
"filters":{
"message_type":"gll"
},
"latitude":"data.split(\",\")[1]",
"longitude":"data.split(\",\")[2]"
import { createSelector } from "reselect";
const getItems = state => state.products.get("items");
export const getRenderableItems = createSelector([getItems], items => {
return items;
});
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);
(ns anthology.json
(:require [clojure.string :as str]))
(def escape-characters
{\return "\\r"
\newline "\\n"
\tab "\\t"
\\ "\\\\"
\" "\\\""})
(ns anthology.xhtml
"XML/HTML emitter"
(:require [clojure.string :as str]))
(defn- yoke [& xs] (apply str (flatten xs)))
(def escape-characters
{\" """
\' "'"
\& "&"
/*
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
@amalantony
amalantony / bind.js
Created February 12, 2017 07:56
Function.prototype.bind implementation.
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)))
}
}
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 {
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