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
// from https://github.com/iamkun/dayjs/issues/1619#issuecomment-1185714859 | |
const round: PluginFunc = (option, dayjsClass) => { | |
dayjsClass.prototype.round = function (amount, unit) { | |
const mod = this.get(unit as UnitType) % amount; | |
if(mod < amount / 2) { | |
return this.subtract(mod, unit).startOf(unit); | |
} |
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
// npm install mapshaper --save | |
import mapshaper from 'mapshaper' | |
// Example: converting a directory of Shapefiles to GeoJSON | |
mapshaper.runCommands('-i shapefiles/*.shp -o geojson/ format=geojson'); |
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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"s3:ListAllMyBuckets" | |
], | |
"Resource": "arn:aws:s3:::*" | |
}, |
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
[ | |
{ | |
"AllowedHeaders": [ | |
"*" | |
], | |
"AllowedMethods": [ | |
"GET", | |
"HEAD" | |
], | |
"AllowedOrigins": [ |
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 delay(time) { | |
return new Promise(resolve => setTimeout(resolve, time)); | |
} | |
// usage: | |
console.log("Thing one") | |
await delay(2000) | |
console.log("Thing two, two seconds later") |
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
// based on: https://stackoverflow.com/a/67136959 | |
const niceRounder = (number) => { | |
let near = 1 | |
if (number > 100) near = 10 | |
if (number > 1000) near = 100 | |
if (number > 10000) near = 1000 | |
if (number % near === 0) return number; |
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
[{"name":"Alabama","nyt":"Ala.","postal":"AL"}, | |
{"name":"Alaska","nyt":"Alaska","postal":"AK"}, | |
{"name":"Arizona","nyt":"Ariz.","postal":"AZ"}, | |
{"name":"Arkansas","nyt":"Ark.","postal":"AR"}, | |
{"name":"California","nyt":"Calif.","postal":"CA"}, | |
{"name":"Colorado","nyt":"Colo.","postal":"CO"}, | |
{"name":"Connecticut","nyt":"Conn.","postal":"CT"}, | |
{"name":"Delaware","nyt":"Del.","postal":"DE"}, | |
{"name":"District of Columbia","nyt":"D.C.","postal":"DC"}, | |
{"name":"Florida","nyt":"Fla.","postal":"FL"}, |
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
const time_hash = Date.now().toString(36); | |
// reverse it for more wordiness: | |
const time_hash2 = Date.now().toString(36).split("").reverse().join("") |
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
const dayjs = require('dayjs') | |
const customParseFormat = require('dayjs/plugin/customParseFormat') | |
dayjs.extend(customParseFormat) | |
const reading_date = dayjs(reading.t, 'M/D/YYYY HH:mm:ss A') | |
// is the month of adding a day the same as the month of adding a month? | |
if ( reading_date.add(1, 'day').get('month') == reading_date.add(1, 'month').get('month') ){ |
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
// nifty trick to bring in json files using require in a module | |
import { createRequire } from "module"; // Bring in the ability to create the 'require' method | |
const require = createRequire(import.meta.url); // construct the require method | |
const trainData = require('./src/data/latest.json') |
NewerOlder