Skip to content

Instantly share code, notes, and snippets.

View barisere's full-sized avatar

Barisere Jonathan barisere

View GitHub Profile
@barisere
barisere / find_pi.cpp
Created March 12, 2017 20:44
The Pi Day Challenge for the Most Descriptive Code in C++
/*Pi Day Challenge: compute an estimate of pi by observing the
*probability
*that randomly generated points within a square fall inside of a circle
*inscribed in the square, given that the square's length is the
*diameter of the circle.
*
*Solution by Jonathan Barisere ([email protected])
*/
#include <iostream>
@barisere
barisere / demystifying github speaker notes.md
Last active February 10, 2018 14:57
Demystifying GitHub speaker notes

Demystifying GitHub speaker notes

Umesi Obusor Ezekiel

What is GitHub

  • An online collaboration platform for everyone.
  • A social coding platform.
@barisere
barisere / project-euler-problem-8.js
Last active September 24, 2018 13:16
My first attempt at Problem 8, Project Euler
/**
* This is my first attempt at Problem 8 (Largest product in a series), Project Euler.
* @see https://projecteuler.net/problem=8
*/
const numbers = `73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
const deleteRequests = new WeakMap<Element, number>();
const delayDeleteResource = function (resourceId: string, delay: number) {
const request = new XMLHttpRequest()
request.open('DELETE', `https://yourdomain/resource/${resourceId}`, true);
// other steps for initializing the request, attaching listeners, ...
return setTimeout(request.send.bind(request), delay);
}
const deleteHandler = {
handleEvent: (event: Event) => {
event.stopPropagation();
const id = event.srcElement.getAttribute('resourceId');
deleteRequests.set(event.srcElement, delayDeleteResource(id, 10000));
}
}
const cancelDeleteRequest = function (source: Element) {
clearTimeout(deleteRequests.get(source));
return deleteRequests.delete(source);
}
const deleteRequestMap = new Map<string, number>();
const deleteResourceOnTimeout = (id: string, delay: number) => setTimeout(() => {
console.info(`Deleting ${id}`);
// actually delete id
deleteRequestMap.delete(id);
}, delay);
const cancelDeleteResource = (id: string) => {
clearTimeout(deleteRequestMap.get(id));
router.delete('/resource/:id', (req, res) => {
const id = req.params.id;
deleteRequestMap.set(id, deleteResourceOnTimeout(id, 10000));
res.status(200).json({ cancelId: deleteRequestMap.get(id) }).end();
});
router.get('/resource/:id/cancelDelete', (req, res) => {
const id = req.params.id;
clearTimeout(deleteRequestMap.get(id));
res.status(200).json({ message: 'Request cancelled' }).end();
// undo-queue.js
"use strict";
const crypto = require("crypto");
const Queue = require("bull");
const undoQueueWorkers = new Map();
const { redis: redisConfig } = require("../config");
function makeJobId (task) {
const hash = crypto.createHash("md5");
hash.update(JSON.stringify(task), "utf8");
return hash.digest("hex");
}
/**
* Registers `workerFn` as a function for adding and processing tasks.
* The tasks are identified by workerFn's name property, so use named functions.
*