Skip to content

Instantly share code, notes, and snippets.

View useEffect.js
function App() {
let divRef = useRef(null);
useEffect(() => {
var text = document.createTextNode(" Rendered ");
return () => {
var text = document.createTextNode(" Unrendered ");


Many people use Redis for a simple message broker. RedisMQ is a trivial layer on Redis and StackExchange.Redis that probably does not work. It provides two simple messaging patterns:

Publish / subscribe

A publisher publishes messages. 0, 1 or more consumers subscribe to the messages.

View gist:4639397
(function (root) {
// declare a module and its dependencies
root.define = function define(name, dependencies, moduleFactory) {
root.amdModules = root.amdModules || {};
if (!_.isArray(dependencies) && typeof dependencies !== 'function')
throw new Error('dependencies must be an array. moduleFactory must be a function.');
root.amdModules[name] = {
'moduleFactory': moduleFactory || dependencies,
liammclennan /
Created Jul 12, 2012
A Backbone Application Framework

Backbone is a library of tools that simplify the design and implementation of client-side web applications. It is explicitly not a framwework. Backbone does not provide guidance about how to assemble an application. This post will be an initial attempt at filling that gap. It assumes an intermediate level of Backbone.js knowledge. If you have never used Backbone.js try Backbone.js Basics or the Backbone.js homepage.

The Application Root

I like to provide a root object/namespace for my application. Let's call it app.

var app = {};

Register Components on the Application Object

liammclennan /
Created May 30, 2012
Object-object Mapping - Why I don't use Automapper

Object-object Mapping - Why I don't use Automapper

At the boundaries of an application it is often nice to map objects from one form to another. The most common example is mapping domain entities to view models, or mapping to dtos for network transfer.

Automapper is a library for removing the duplication from object-object mapping code by mapping by convention. When the conventions don't map the way you want you can explicitly map properties.

After using AutoMapper on a couple of projects I have stopped using it. The problem is that the convention based mappings introduce annoying bugs when property names change or the object graph changes. When a change breaks the convention it results in a runtime exception. Very annoying.

What I Do Instead

liammclennan / gist:542cb1264305f525c70b
Created May 27, 2015
Partitioning events with (linqpad - reference and Rx-main)
View gist:542cb1264305f525c70b
void Main()
var system = ActorSystem.Create("MySystem");
var greeters = system.ActorOf(Props.Create(() => new DeviceSplitter()));
var r = new System.Random();
var measures = Enumerable.Repeat(new [] {"a","b","c","d"}, 250000)
.SelectMany(c => c)
.Select (id => new Measure(id,r.Next()));
foreach (var m in measures) greeters.Tell(m);
liammclennan /
Created Jun 7, 2012
Backbone.js Style / Patterns

Naming Rules

Use PascalCase for constructors, namespaces and modules:

var m = new Backbone.Model(); 

Prefix private properties with _

This is a convention to compensate for JavaScript's lack of private properties on objects. Being able to identify private methods is important because it tells us that we don't need to test those methods and that they will not be coupled to anything outside of the object.

liammclennan / skeleton.js
Created Aug 24, 2017
Node.js console application skeleton
View skeleton.js
if (process.argv.length < 3) {
console.log('Usage: node ' + process.argv[1] + ' FILENAME');
var fs = require('fs')
, filename = process.argv[2];
let input = fs.readFileSync(filename, 'utf8');
liammclennan / gist:4957758
Created Feb 15, 2013
mapMany (SelectMany) in JavaScript
View gist:4957758
function mapMany (arr, mapper) {
return arr.reduce(function (prev, curr, i) {
return prev.concat(mapper(curr));
// usage
var res1 = mapMany(['abcd', '1234'], function (item) {
return item.split('');
liammclennan / leftrotation.fs
Created Mar 16, 2017
Hackerrank: Arrays: Left Rotation
View leftrotation.fs
let rotations = System.Console.ReadLine().Split().[1] |> int
let vals = System.Console.ReadLine().Split()
let rotate arr n =
let cut = n % Array.length arr
Array.append arr.[cut..] arr.[..cut-1]
String.concat " " (rotate vals rotations) |> printfn "%s"