Skip to content

Instantly share code, notes, and snippets.

Jason Diamond jdiamond

Block or report user

Report or block jdiamond

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jdiamond / Dockerfile
Created Nov 16, 2017
SSH certificates
View Dockerfile
FROM alpine
# Install OpenSSH:
RUN apk -U add openssh
# Generate host keys:
RUN ssh-keygen -A
# Create users:
RUN adduser -D user1
jdiamond /
Created Aug 16, 2017
Testing React apps and components

"Injecting" configuration into a create-react-app is done with environmental variables. I always have at least one for the root of my REST API or GraphQL endpoint.

When running in development, I set that variable to point at a local version of the backend server I have running on my laptop. That's some other project that I do whatever I need to in order to get it running and available to accept requests from my React app.

If I wanted to start simple with static JSON files, maybe I would use something

jdiamond /
Last active Nov 15, 2016
systemd OUI service

This unit file changes the OUI in the MAC addresses for enabled interfaces. It leaves the remaining bytes as is.

Copy oui@.service to /etc/systemd/system.

Enable it for each interface like this:

sudo systemctl enable oui@eth0
sudo systemctl enable oui@wlan0
jdiamond /
Created Jun 2, 2015
Enable swapfile on Ubuntu
# create the swapfile:
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
# enable it:
swapon /swapfile
sysctl vm.swappiness=10
sysctl vm.vfs_cache_pressure=50
jdiamond / memory.js
Last active Aug 29, 2015
Watch memory and dump heaps in Node.js
View memory.js
function startWatchingMemory() {
if (process.env.MEMWATCH) {
var memwatch = require('memwatch-next');
var heapdump = process.env.HEAPDUMP && require('heapdump');
var hd = null;
memwatch.on('leak', function(info) {
jdiamond / Vagrantfile
Created Aug 11, 2014
Yeoman Vagrantfile
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install -y nodejs
View intersect.js
var arr1 = [ { name: 'Nikki' }, { name: 'Jason' }, { name: 'Thanh' } ];
var arr2 = [ { name: 'Nikki' }, { name: 'Thanh' } ];
var index = {};
arr1.forEach(function(item) {
index[] = item;
jdiamond / require-mustache.js
Created May 2, 2013
RequireJS Mustache plugin
View require-mustache.js
define([ 'text', 'mustache' ], function(text, Mustache) {
return {
load: function(name, require, callback, config) {
text.load(name, require, function(text) {
}, config);

Your original example:

public virtual List<UserDC> GetAllActiveAgentsByReason(int reasonID)
        if (reasonID < 0)
            throw new ArgumentException("An invalid reasonID was passed.");
jdiamond /
Last active Dec 16, 2015
Promise example for Domenic


This is part of the router in a single-page application I'm working on:

function navigateTo(url) {
    return findOrCreatePageContainer(url)      // finds div or creates new one
        .then(loadAndInitPageIfNotAlreadyDone) // loads content into div
        .catch(injectErrorMessage)             // injects error message into div
        .then(transitionToNewPage);            // displays content in div
You can’t perform that action at this time.