Skip to content

Instantly share code, notes, and snippets.

@carmour24
carmour24 / mapMap.js
Created September 21, 2020 17:00
Quick method for mapping the entries in a map resulting in a new map.
const mapMap = (inputMap, mapping) => {
const _map = (iterator, mapping) => {
const entry = iterator.next()
return entry.done
? []
: [[entry.value[0], mapping(entry.value)], ..._map(iterator, mapping)]
}
const iterator = inputMap[Symbol.iterator]()
const mappingResultEntries = _map(iterator, mapping)
return new Map(mappingResultEntries)
@carmour24
carmour24 / whatsreactive.md
Last active June 20, 2018 16:25
What's this reactive thing anyway?

While researching tech for a new project I've seen sure seen the words react, reactor and reactive come up a lot. Confusingly the term reactive is somewhat overloaded so I'll try to define what we mean by it in which context giving some hopefully clarifying examples. This is just some notes to help me think about this stuff so it might not be 100% right.

As a brief introduction reactive programming is [about non-blocking applications that are asynchronous and event-driven and require a small number of threads to scale vertically (i.e. within the JVM) rather than horizontally (i.e. through clustering).][1]

Let me give a generic example which is pertinent and will hopefully illustrate why this has become a hot topic.

In a typical web server we would have a thread per request model. Meaning that for each request made to the web server a single thread would service this request for its lifetime. The thread may go off and perform some blocking IO, e.g. reading a file, connecting to database or making a call to

@carmour24
carmour24 / index.html
Created March 15, 2018 12:27
Fixed header in a table with a fixed sized table body
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
html {
height: 100%;
}
body {
@carmour24
carmour24 / getRandomElements.js
Last active August 29, 2015 14:07
Function to get a specified number of random elements from an array, optionally filtering using a filter function.
function(elementArray, requiredCount, filter) {
var randomElements = [];
while (randomElements.length < requiredCount) {
var randomIndex = Math.floor(Math.random() * elementArray.length);
// If no filter function has been provided or the filter function returns true
// then add the element to the random array.
var element = elementArray[randomIndex];
if (!filter || (filter && filter(element, randomIndex, elementArray, randomElements))) {
@carmour24
carmour24 / grunt.js
Created January 8, 2013 17:25 — forked from anonymous/grunt.js
Rubbish wee grunt file to watch a set of files and spawn multimarkdown for any that change. Requires nodejs, grunt and multimarkdown installed and in the path env.
/*global module:false process:false*/
var path = require('path');
var child_process = require('child_process');
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
watch: {
'markdown': {
@carmour24
carmour24 / static_server.js
Created September 14, 2012 11:16 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument. If the requested file is a directory it will return the content of the base index.htm file. Requires mime package.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
port = process.argv[2] || 8888,
mime;
try {
mime = require("mime");
}