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
var _ = require('lodash'); | |
function zfc(strings, ...values) { | |
return _(strings).zip(values).flatten().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
function loadFilters() { | |
FiltersModel.getSegments().then( | |
segments => { | |
segments.forEach(segment => { | |
FiltersModel.getSegmentTerms(segment).then( | |
segmentTerms => { | |
console.log(segmentTerms); | |
}, | |
console.error | |
); |
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
async function loadFilters() { | |
let segments = await FiltersModel.getSegments().catch(console.error); | |
segments.forEach(async segment => { | |
let segmentTerms = await FiltersModel.getSegmentTerms(segment).catch(console.error); | |
console.log(segmentTerms); | |
}); | |
} |
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
"use strict"; | |
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | |
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | |
function loadFilters() { | |
return _loadFilters.apply(this, arguments); | |
} |
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
#!/usr/bin/env bash | |
message="$1" | |
key="$2" | |
algorithm="sha1" | |
echo "$message" | base64 | openssl "$algorithm" -hmac "$key" |
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
package main | |
import ( | |
"fmt" | |
"os" | |
"sort" | |
"text/tabwriter" | |
"unsafe" | |
) |
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
// https://medium.com/star-gazers/improving-tail-latency-with-request-hedging-700c77cabeda | |
async function fetchHedged(url, { timeout }) { | |
let res; | |
try { | |
res = await fetch(url, { | |
signal: AbortSignal.timeout(timeout) | |
}) | |
} catch (error) { | |
if (error && error.code !== 'ABORT_ERR') { | |
throw error |
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
import { randomBytes, createHash } from 'node:crypto' | |
const ZERO_WIDTH_SPACE = '' | |
const ZERO_WIDTH_JOINER = '' | |
const randomZeroWidthHash = () => | |
randomBytes(32) | |
.reduce((a, b) => [...a, b.toString(2)], []) | |
.reduce((a, c) => a + (+c ? ZERO_WIDTH_SPACE : ZERO_WIDTH_JOINER), '') | |
.padEnd(256, ZERO_WIDTH_SPACE) |
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 dateDiff = (startDate, endDate) => { | |
const startUTC = dateToUTC(startDate); | |
const endUTC = dateToUTC(endDate); | |
const diffMilliseconds = endUTC - startUTC; | |
const millisecondsPerDay = 1000 * 60 * 60 * 24; | |
const diffDays = diffMilliseconds / millisecondsPerDay; | |
const [years, yearsRem] = floordivmod(diffDays, 365); | |
const [months, monthsRem] = floordivmod(yearsRem, 30); |