Skip to content

Instantly share code, notes, and snippets.

View luciyer's full-sized avatar
🐋

Luc Iyer luciyer

🐋
View GitHub Profile
@luciyer
luciyer / BatchQuery.js
Created January 21, 2021 23:26
Batch execution against a list of items with sleep interval
class BatchQuery {
constructor(connection, queryList, batchSize = 10, sleepMs = 1000) {
this.connection = connection
this.queryList = queryList
this.batchSize = batchSize
this.sleepMs = sleepMs
this.queryResults = []
}
@luciyer
luciyer / app.js
Created November 27, 2020 05:47
Express + Mongoose Middleware: Standard Controller + Router
const express = require("express")
const mw = require("./middleware")
const app = express()
app
.use(express.json())
.use(express.urlencoded({ extended: true }))
.use(mw.Book.router)
@luciyer
luciyer / index.html
Last active November 17, 2020 00:34
bull.js job processing with socket.io
<!DOCTYPE HTML>
<html lang="en">
<head>
</head>
<body>
<h1>Socketzzz</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.1/socket.io.js"
integrity="sha512-vGcPDqyonHb0c11UofnOKdSAt5zYRpKI4ow+v6hat4i96b7nHSn8PQyk0sT5L9RECyksp+SztCPP6bqeeGaRKg=="
crossorigin="anonymous">
@luciyer
luciyer / d3GaugeChart.js
Last active April 13, 2021 02:15
Configurable Gauge Chart using D3.js
/* DEMO: https://observablehq.com/@luciyer/exportable-gauge */
/* USAGE */
let chart = GaugeChart();
// Optionally - set properties - these are defaults:
/*
chart.setProperties({
rotation: 0,
@luciyer
luciyer / svgGradientDefs.js
Created November 5, 2020 23:16
Javascript function to generate SVG gradient <defs> object
/*
Dependent on d3.js.
*/
const svgGradientDefs = (color_array, gradient_id) => {
if (color_array.length < 2)
throw new Error("Argument should be array of two or more colors.")
var pctStep = 100 / (color_array.length - 1),
@luciyer
luciyer / emitter.js
Created October 11, 2020 01:23
Mongoose Hooks to Emit Events
const events = require("events")
module.exports = new events.EventEmitter();
@luciyer
luciyer / agenda.js
Last active August 19, 2020 19:17
REST "agenda" with long-running jobs
require("dotenv").config()
const Agenda = require("agenda")
const jobs = require("./jobs")
const db_uri = process.env.MONGODB_URI || "mongodb://localhost/dev"
const connection_options = {
db : {
address: db_uri,