Skip to content

Instantly share code, notes, and snippets.

View jdiamond's full-sized avatar

Jason Diamond jdiamond

  • 14:06 (UTC -07:00)
View GitHub Profile
@jdiamond
jdiamond / indexeddb.html
Created September 16, 2012 22:25
IndexedDB Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IndexedDB Example</title>
</head>
<body>
<h1>IndexedDB Example</h1>
<p>
@jdiamond
jdiamond / Dockerfile
Created November 16, 2017 02:24
SSH certificates
FROM alpine
# Install OpenSSH:
RUN apk -U add openssh
# Generate host keys:
RUN ssh-keygen -A
# Create users:
RUN adduser -D user1
@jdiamond
jdiamond / package.json
Created September 11, 2020 03:12
top-level await
{
"type": "module"
}
@jdiamond
jdiamond / mongoose-as-promised.js
Created December 30, 2012 18:58
Mongoose as Promised
var mongoose = require('mongoose');
var Q = require('q');
mongoose.Promise.prototype.then = function(fulfilled, rejected) {
var deferred = Q.defer();
this.addCallback(deferred.resolve);
this.addErrback(deferred.reject);
return deferred.promise.then(fulfilled, rejected);
@jdiamond
jdiamond / notes.md
Created August 16, 2017 21:55
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
jdiamond / oui.md
Last active November 15, 2016 21:32
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
jdiamond / require-mustache.js
Created May 2, 2013 02:31
RequireJS Mustache plugin
define([ 'text', 'mustache' ], function(text, Mustache) {
return {
load: function(name, require, callback, config) {
text.load(name, require, function(text) {
callback(Mustache.compile(text));
}, config);
}
};
});

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 December 16, 2015 13:19
Promise example for Domenic

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
using System;
using NUnit.Framework;
namespace BehaveN.Tests
{
[TestFixture]
public class Describe_NameParser
{
[Test]
public void it_should_throw_an_exception_when_parsing_null()