Skip to content

Instantly share code, notes, and snippets.

View dsernst's full-sized avatar
🧘‍♂️
practicing mindfulness

David Ernst dsernst

🧘‍♂️
practicing mindfulness
View GitHub Profile
@dsernst
dsernst / heapsPermute.js
Last active May 15, 2018 22:53
A JavaScript implement of Heap's efficient Permutation Algorithm: https://en.wikipedia.org/wiki/Heap%27s_algorithm
var swap = function (array, pos1, pos2) {
var temp = array[pos1];
array[pos1] = array[pos2];
array[pos2] = temp;
};
var heapsPermute = function (array, output, n) {
n = n || array.length; // set n default to array.length
if (n === 1) {
output(array);

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@dsernst
dsernst / mergeSort.js
Created January 17, 2015 22:42
Merge Sort in JavaScript
var mergeSort = function(array) {
if (array.length === 1) {
return array
} else {
var split = Math.floor(array.length/2)
var left = array.slice(0, split)
var right = array.slice(split)
left = mergeSort(left)
right = mergeSort(right)
@dsernst
dsernst / makeRotatedArray.js
Created February 5, 2015 03:33
A function to make randomize sorted&rotated arrays, for testing the time complexity of rotatedArraySearch.
function makeRotatedArrays (size) {
var array = [];
for (var i = 0; i < size; i++) {
array.push(Math.floor(Math.random() * size * 2));
}
array = array.sort(function (a, b) {return a - b});
var rotationMagnitude = Math.floor(Math.random() * size);
@dsernst
dsernst / 15 Lattice pairs.js
Created February 6, 2015 17:18
Project Euler problem 15
// Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
// How many such routes are there through a 20×20 grid?
var perimeter = 1;
var routes = 1;
var move = function (x, y) {
if (x < perimeter && y < perimeter) {
@dsernst
dsernst / testAHash.js
Created February 11, 2015 18:10
To see if a given hash is evenly distributed.
var getIndexBelowMaxForKey = function(str, max){
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = (hash<<5) + hash + str.charCodeAt(i);
hash = hash & hash; // Convert to 32bit integer
hash = Math.abs(hash);
}
return hash % max;
};
@dsernst
dsernst / keybase.md
Created February 18, 2015 06:08
Verifying identity for http://keybase.io

Keybase proof

I hereby claim:

  • I am dsernst on github.
  • I am dsernst (https://keybase.io/dsernst) on keybase.
  • I have a public key whose fingerprint is 257F 5B97 C1C5 F97A 7071 13D2 42B1 F2E6 A8B9 F8C0

To claim this, I am signing this object:

@dsernst
dsernst / Unified-Cloud-Formation.json
Created March 24, 2015 18:17
Template for setting up your own private and secure VPN on AWS.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Setting up your own private and secure VPN. You can read instructions on our blog https://www.webdigi.co.uk/blog/2015/how-to-setup-your-own-private-secure-free-vpn-on-the-amazon-aws-cloud-in-10-minutes/ and you can follow video instructions on Youtube https://www.youtube.com/watch?v=fBBERp5CUgo",
"Mappings": {
"AWSInstanceType2Arch": {
"High.Speed.VPN-Paid": {
"InstanceType": "t2.medium"
},
"Standard.VPN-Free": {
"InstanceType": "t2.micro"
@dsernst
dsernst / git-wiki-options.md
Created May 9, 2015 01:02
research on using git to power a wiki
// ?id=<GOOGLE_SHEET_ID>
function doGet(request) {
if (!request.parameter.id) {
return ContentService.createTextOutput(JSON.stringify(new Error('no Google Sheet id set')))
.setMimeType(ContentService.MimeType.JSON);
}
var cache = cacheNotesAndFormulas(request.parameter.id);
// Return cache as JSON