Skip to content

Instantly share code, notes, and snippets.

View onosendi's full-sized avatar

Daniel Lindegren onosendi

View GitHub Profile
async function foo() {
try {
const { pointer_id } = await db('pointer')
.where({ report: 'foo-report' })
.first();
const data = await db('data').where('id', '>', pointer_id);
const report = makeReport(data);
// Function abstraction of try/catch
const fetch = () => new Promise((resolve, reject) => {
setTimeout(() => {
const fn = Math.floor(Math.random() * 2) % 2 ? resolve : reject;
fn('Foo');
}, 100);
});
// Function abstraction of try/catch
const fetch = () => new Promise((resolve, reject) => {
setTimeout(() => {
const fn = Math.floor(Math.random() * 2) % 2 ? resolve : reject;
fn('Foo');
}, 100);
});
const foo = (str, res = '') => (Number.isNaN(Number.parseInt(str[0], 10))
? res
: foo(str.slice(1), res + str[0]));
console.log(foo('4528 Date: ORDER'));
const R = require('ramda');
const xs = [
{
agent: 'Kim', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Frank', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
const xs = [
{
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Kayla', ring_time: 1, queue_id: 1, talk_time: 1,
},
function splitEvery(n, arr) {
const res = [];
let i = 0;
while (i < arr.length) {
res.push(arr.slice(i, i += n));
}
return res;
// Recursive promises
const resolvePromises = (promises, result = []) => {
if (!promises.length) {
return Promise.resolve(result);
}
return promises[0]
.then((response) => resolvePromises(promises.slice(1), result.concat(response)));
};
const R = require('ramda');
const userRegAttrs = [
{ reg_id: 1, attr_name: 'foo', attr_value: 1 },
{ reg_id: 1, attr_name: 'bar', attr_value: 3 },
];
const user_id = 1;
const res = userRegAttrs.map((obj) => {
const R = require('ramda');
const userRegAttrs = [
{ reg_id: 1, attr_name: 'foo', attr_value: 1 },
{ reg_id: 1, attr_name: 'bar', attr_value: 3 },
];
const user_id = 1;
const res = R.pipe(