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
const EARTH_CIR_METERS = 40075016.686; | |
function toRadians(degrees) { | |
return degrees * Math.PI / 180; | |
}; | |
function degreeWidth(lat){ | |
return EARTH_CIR_METERS / 360 * Math.cos(toRadians(lat)); | |
} |
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
const EARTH_CIR_METERS = 40075016.686; | |
function toRadians(degrees) { | |
return degrees * Math.PI / 180; | |
}; | |
const metersToPixels = (meters, latitude, zoom) => { | |
const metersPerPixel = EARTH_CIR_METERS / Math.pow(2, zoom + 8) * Math.cos(toRadians(latitude)); | |
return meters / metersPerPixel | |
} |
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
// define window.sheetId sometime before loading this script. the sheet id is in the URL of the Google Sheet when you're editing it. | |
if(!window.sheetId) throw Error('window.sheetId required'); | |
class DataProvider { | |
constructor(sheetId) { | |
this.sheetId = sheetId; | |
this.dataPromises = {}; | |
} |
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
const fs = require('fs'); | |
const path = require('path'); | |
function getMostRecentFile(dir) { | |
const files = fs.readdirSync(dir); | |
let earliestCreate = 0; | |
let mostRecentFile = files[0]; | |
files.forEach(file => { | |
if (fs.statSync(path.join(dir, file)).ctime > earliestCreate) { |
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
const EARTH_CIR_METERS = 40075016.686; | |
const degreesPerMeter = 360 / EARTH_CIR_METERS; | |
function toRadians(degrees) { | |
return degrees * Math.PI / 180; | |
}; | |
function latLngToBounds(lat, lng, zoom, width, height){ | |
const metersPerPixelEW = EARTH_CIR_METERS / Math.pow(2, zoom + 8); | |
const metersPerPixelNS = EARTH_CIR_METERS / Math.pow(2, zoom + 8) * Math.cos(toRadians(lat)); |
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; |
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
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
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
eslint "**/**.js" -f unix | perl -n -l -e '/(.*\.js):(\d*):/ && print "$1 $2"' | xargs -n 2 sh -c 'git blame $0 -L$1,$1' |
NewerOlder