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
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
jdiamond / notes.md
Created Aug 16, 2017
Testing React apps and components
View notes.md

"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
jdiamond / oui.md
Last active Nov 15, 2016
systemd OUI service
View oui.md

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
jdiamond / swap.sh
Created Jun 2, 2015
Enable swapfile on Ubuntu
View swap.sh
# 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
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) {
log(info);
@jdiamond
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!
VAGRANTFILE_API_VERSION = "2"
INSTALL_NODE = <<SCRIPT
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.name] = item;
});
console.log(index);
@jdiamond
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) {
callback(Mustache.compile(text));
}, config);
}
};
});
View exceptions.md

Your original example:

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

Problem

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.