Skip to content

Instantly share code, notes, and snippets.

@therightstuff
therightstuff / restify_with_cors.js
Last active February 12, 2018 08:20
CORS middleware for restify
// MIDDLEWARE
// must be defined before routing configured
server.use(restify.plugins.bodyParser());
server.use(restify.plugins.queryParser());
// CORS must be first
var allowedMethods = [
"OPTIONS",
@therightstuff
therightstuff / exampleWorker.js
Created May 11, 2018 12:50
Web Worker callback design pattern
// ensure window object available
var window = self;
self.addEventListener('message', function (e) {
var payload = e.data;
var result = null;
var err = null;
switch (payload.cmd) {
case 'sampleCommand':
@therightstuff
therightstuff / inheritance.js
Created September 11, 2018 22:56
simple node.js inheritance example
var util = require("util");
// simple class
function A() {
this.self= this;
this.className = "classA";
this.myVar = "ownerA";
}
// class methods
@therightstuff
therightstuff / JSON-CSV.html
Last active February 21, 2019 10:51
Online JSON / CSV Converter
<html>
<head>
<title>Online JSON / CSV Converter</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://fastcdn.org/FileSaver.js/1.1.20151003/FileSaver.js"></script>
<script language="javascript">
var conversionStyle;
var prefixConnector;
var delimiter, delimiterCharacter;
@therightstuff
therightstuff / keybase.md
Created March 3, 2019 20:05
keybase proof of identity

Keybase proof

I hereby claim:

  • I am therightstuff on github.
  • I am therightstuff (https://keybase.io/therightstuff) on keybase.
  • I have a public key ASDOnjEkmg8wYq0rWQpvUcp4uItnJCBTX_5EBOrm7FcPjAo

To claim this, I am signing this object:

@therightstuff
therightstuff / MigrationsList.json
Last active September 11, 2019 21:42
How to code Entity Framework programmable migrations
[
"201704230706451_AutomaticMigration",
"201704230705538_AutomaticMigration"
]
@therightstuff
therightstuff / add_parent.sh
Last active March 24, 2020 18:35
add a parent commit to an existing git commit
#!/bin/bash
# add a parent commit to the specified commit, ideal
# for establishing the other parent of a squashed merge
# lifted from https://stackoverflow.com/a/41243690/2860309
# usage: ./add_parent.sh TARGET_COMMIT_ID NEW_PARENT_COMMIT_ID
set -ex
target_commit=$1
@therightstuff
therightstuff / fairShuffle.js
Last active March 28, 2020 12:56
A list shuffle method that ensures every item is consumed
/*
Motivation:
A shuffler that ensures that no items in a list (a music playlist in particular) are left behind.
Mechanism:
When an item in the current shuffle group is used, it is moved to the next shuffle group and the next shuffle group is reshuffled.
Shuffling the current group doesn't affect the number of items remaining in the current shuffle group.
Drawback:
Shuffling the current group when there's only one item remaining will have no effect, the item must be consumed (to preserve fairness) and only then will be shuffled in to the next group
@therightstuff
therightstuff / AES.cs
Last active April 4, 2020 21:01
Simple AES 256 CBC Encryption to and Decryption from Base64 encoded strings in C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
namespace MyProject.Data.Encryption
{
public class AES
{
// https://stackoverflow.com/a/18502617/2860309
@therightstuff
therightstuff / README.md
Last active June 23, 2020 09:54
Code samples for A templated guide to AWS serverless development with CDK