This file contains hidden or 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
| <html> | |
| <head> | |
| <style> | |
| body{ | |
| font-family: sans-serif; | |
| } | |
| #spark{ | |
| font-size: 90px; | |
| font-weight: bold; |
This file contains hidden or 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
| //example: | |
| //var nestedObj = {planet: {earth: {'@continent': 'africa'}}}; | |
| //hasOwnProperties(nestedObj, 'planet.earth.@continent') //returns true | |
| //hasOwnProperties(nestedObj, 'planet.earth.@continent', 'africa') //returns true | |
| //hasOwnProperties(nestedObj, 'planet.earth.unicorns') //returns false | |
| hasOwnProperties: function(target, path, value){ | |
| if (typeof target !== 'object' || target === null) { return false; } | |
| var parts = path.split('.'); |
This file contains hidden or 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
| #include <MIDI.h> | |
| const byte tones = 12; | |
| const byte midiStart = 36; | |
| const byte onDebounce = 10; | |
| const byte offDebounce = 60; | |
| const byte pedalPins[] = {2, 3, 4, 5, 6, 7, 8, A0, A1, 11, 12, A2}; | |
| byte note; | |
| byte playing[tones]; |
This file contains hidden or 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 removeQueryParam(url, param){ | |
| var paramInMiddle = new RegExp('&' + param + '=\\w*'); // ¶m=blah | |
| var paramInFront = new RegExp('\\?' + param + '=\\w*&'); // ?param=blah& | |
| var paramSolo = new RegExp('\\?' + param + '=\\w*'); // ?param=blah | |
| return url | |
| .replace(paramInMiddle, '') | |
| .replace(paramInFront, '?') | |
| .replace(paramSolo, ''); | |
| } |
This file contains hidden or 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
| 'use strict'; | |
| //This reporter shows the slowest specs at the end of a test run | |
| const chalk = require('chalk'); | |
| const specs = {}; | |
| function sortedSpecs(){ | |
| return Object.keys(specs) | |
| .map(key => specs[key]) //convert object to array |
This file contains hidden or 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
| eslint "**/**.js" -f unix | perl -n -l -e '/(.*\.js):(\d*):/ && print "$1 $2"' | xargs -n 2 sh -c 'git blame $0 -L$1,$1' |
This file contains hidden or 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 throttlePromises(elements, asyncForEach, groupSize){ | |
| return new Promise(function(resolve, reject){ | |
| //create a generator object that 'yields' for every group | |
| const genObj = function* gen(){ | |
| while(elements.length > 0){ | |
| yield Promise.all(elements.splice(0, groupSize).map(asyncForEach)) | |
| .then(() => genObj.next()); | |
| } | |
| return resolve(true); | |
| }(); |
This file contains hidden or 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 insistentRequest(request, tryLimit){ | |
| if(!tryLimit) return Promise.reject('tryLimit must be above 0'); | |
| let tries = 0; | |
| return new Promise(function(resolve, reject){ | |
| //create a generator object that repeatedly 'yields' the same promise until it succeeds or the try limit is reached | |
| const genObj = function* gen(){ | |
| while(1){ | |
| yield request() | |
| .then(resolve) |
This file contains hidden or 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
| //divide 360 into 16 equal slices | |
| const degrees = (new Array(16)).fill(null).map((x, i) => 360/16 * i + 11.25); | |
| const directions = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']; | |
| function cardinalDirection(bearing) { | |
| for (let i = 0, l = degrees.length; i < l; i++) { | |
| if (bearing < degrees[i]) return directions[i]; | |
| if (i == l - 1) return directions[0]; | |
| } | |
| } |
This file contains hidden or 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
| // adapted from http://mathforum.org/library/drmath/view/63767.html | |
| const r = 6371.0072; //earth radius in KM | |
| function toRadians(degrees) { | |
| return degrees * Math.PI / 180; | |
| }; | |
| function computeArea(bbox){ | |
| const [minLng, minLat, maxLng, maxLat] = bbox; |