Contact |
---|
20605 1st Ave E Spanaway, WA 98387 |
Cell: (253) 330-7222 |
Email: danielthehug@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* DOM helpers | |
**************************************/ | |
// Get elements by CSS selector: | |
function qs(selector, scope) { | |
return (scope || document).querySelector(selector); | |
} | |
function qsa(selector, scope) { | |
return (scope || document).querySelectorAll(selector); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function runningSum(addends) { | |
var sums = [addends[0]]; | |
for (var i=1; i<addends.length; i++) { | |
sums.push(addends[i]); | |
} | |
return sums; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Call arrayToObj() passing your array and function. | |
function arrayToObj(array, keyValueMap) { | |
var obj = {}; | |
var len = array.length; | |
// Your function will be called for each item in the array. | |
for (var i = 0; i < len; i++) { | |
var curVal = array[i]; | |
// Just like with [].forEach(), your function will be passed the | |
// curent item of the array, its index, and the array it's in. | |
var keyValuePair = keyValueMap(curVal, i, array); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Zip arrays into one | |
// Example with two arrays: value 0 from a, value 0 from b, value 1 from a, etc. | |
function zipArrays() { | |
var zipped = []; | |
var arrays = [].slice.call(arguments); | |
for (var valueI = 0; arrays.length > 0; valueI++) { | |
for (var arrayI = 0; arrayI < arrays.length; arrayI++) { | |
if (arrays[arrayI].length - 1 < valueI) { | |
arrays.splice(arrayI, 1); | |
continue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
usage: | |
var csvString = toCSV({ | |
key1: { col1: 5, col2: 'hi' }, | |
key2: { col1: 7, col2: 'hello' } | |
}, { | |
// default config: | |
includeKeys: true, | |
delimiter: ',', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countingSort(arr, min, max) { | |
var i, z = 0, count = []; | |
for (i = min; i <= max; i++) { | |
count[i] = 0; | |
} | |
for (i=0; i < arr.length; i++) { | |
count[arr[i]]++; | |
} | |
for (i = min; i <= max; i++) { | |
while (count[i]-- > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title><%= documentTitle %></title> | |
<link rel="stylesheet" href="https://daniel-hug.github.io/files/stackedit/base.css" /> | |
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> | |
</head> | |
<body><div class="container"><%= documentHTML %></div></body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pass a function-encased multi-line comment | |
// returns the multi-line string in the comment | |
function hereDoc(f) { | |
// return the function's representation as a string | |
return f.toString() | |
// except, if the string starts with one or more characters other than a forward slash | |
// which are followed by "/*" and then optionally followed by "!", remove this whole prefix. | |
.replace(/^[^/]+\/\*!?/, '') | |
// and, if "*/" appears followed by one or more characters other | |
// than a forward slash to end the string, remove this whole suffix. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pass a function-encased multi-line comment | |
// returns the multi-line string in the comment | |
function hereDoc(f) { | |
// return the function's representation as a string | |
return f.toString() | |
// except, if the string starts with one or more characters other than a forward slash | |
// which are followed by "/*" and then optionally followed by "!", remove this whole prefix. | |
.replace(/^[^/]+\/\*!?/, '') | |
// and, if "*/" appears followed by one or more characters other | |
// than a forward slash to end the string, remove this whole suffix. |