Skip to content

Instantly share code, notes, and snippets.

@tlumko
tlumko / promiseTimeout.js
Last active August 20, 2018 12:13
Promise timeout
function promiseTimeout(promise, ms){
let timerId;
let timeout = new Promise((resolve, reject) => {
timerId = setTimeout(() => reject('timeout'), ms);
});
return Promise.race([
timeout,
promise.then(r => {
clearTimeout(timerId);
@tlumko
tlumko / audit-log.js
Created August 27, 2018 13:06
Node sequelize audit log
const AuditLog = auditLogDb.define('audit-log', {
userId: {
type: Sequelize.DataTypes.INTEGER,
allowNull: true,
},
actionType: {
type: Sequelize.DataTypes.STRING,
allowNull: false,
},
table: {
@tlumko
tlumko / createEnum.js
Created August 29, 2018 05:57
Create enum
function createEnum(arr) {
const obj = arr.reduce((accum, item, index) => {
index = index.toString();
accum[index] = item;
accum[item] = index;
return accum;
}, {});
Object.defineProperties(obj, {
names: {