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 doublingTime(date1, value1, date2, value2) { | |
const diff = Math.ceil(date2.getTime() - date1.getTime()) / 86400000; | |
const days = Math.log(2) * diff / (Math.log(value2) - Math.log(value1)); | |
return days; | |
} | |
// Usage: | |
// doublingTime(new Date('2020-04-01'), 300, new Date('2020-04-05'), 900); | |
// => 2.523719014285829 |
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
// Convert JSON to a CSV string | |
function jsonToCsv(json) { | |
const replaceEmpty = (key, value) => { | |
return value === null ? '' : value; | |
}; | |
const parseRow = row => { | |
return header.map(fieldName => | |
JSON.stringify(row[fieldName], replaceEmpty) | |
).join(','); | |
}; |
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
# Read more about Slack webhooks here: https://api.slack.com/messaging/webhooks | |
curl -X POST \ | |
-H 'Content-type: application/json; charset=utf-8' \ | |
--data '{ "channel": "#mychannel", "username": "superbot", "icon_emoji": ":bot:", "text": "Foo" }' \ | |
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX |
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 https = require('https'); | |
exports.postToSlack = () => { | |
// Read more about Slack webhooks here: https://api.slack.com/messaging/webhooks | |
const webhookPath = '/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' | |
const payload = { | |
'channel': '#mychannel', | |
'username': 'slackbot', |
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
// Convert CSV string to JavaScript object array | |
const parseCSV = (string) => { | |
const removeEmpty = (string) => string.length > 0; | |
const removeQuotes = (string) => string.length > 0 ? string.replace(/^["'](.*)["']$/, '$1') : undefined; | |
const lines = string.split(/\r?\n/).filter(removeEmpty); | |
const rows = lines.map(line => line.split(/,|;/).map(removeQuotes)); | |
return rows.reduce((accArr, currRow, rowIndex) => { | |
if (rowIndex != 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
find . -name "node_modules" -type d -prune -exec rm -rf '{}' + |
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 results = [ | |
{ party: 'socialists', votes: 130755 }, | |
{ party: 'conservatives', votes: 102068 }, | |
{ party: 'liberals', votes: 34012 }, | |
{ party: 'greens', votes: 31090 }, | |
{ party: 'crazypeople', votes: 11111 } | |
]; | |
const hareNiemeyer = (results, seats) => { |
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 quantizeScale = (arr, min, max) => { | |
const steps = colors.length; | |
const increment = (max - min) / steps; | |
const bins = Array.apply(undefined, Array(steps)).map((bin, index) => (index * increment) + min); | |
return value => { | |
for (let i = 0; i < bins.length; i++) { | |
if (value <= bins[i]) { | |
return colors[i]; |
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
gs \ | |
-o fixed.pdf \ | |
-sDEVICE=pdfwrite \ | |
-dPDFSETTINGS=/prepress \ | |
broke.pdf |
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 os = require('os'); | |
const path = require('path'); | |
const cluster = require('cluster'); | |
const lockFile = require('lockfile'); | |
const filePath = path.resolve(__dirname, 'result.json'); | |
const lockPath = path.resolve(__dirname, 'result.json.lock'); |