- An online collaboration platform for everyone.
- A social coding platform.
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
/*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> |
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
/** | |
* 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 |
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 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); | |
} |
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 deleteHandler = { | |
handleEvent: (event: Event) => { | |
event.stopPropagation(); | |
const id = event.srcElement.getAttribute('resourceId'); | |
deleteRequests.set(event.srcElement, delayDeleteResource(id, 10000)); | |
} | |
} |
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 cancelDeleteRequest = function (source: Element) { | |
clearTimeout(deleteRequests.get(source)); | |
return deleteRequests.delete(source); | |
} |
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 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)); |
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
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(); |
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
// undo-queue.js | |
"use strict"; | |
const crypto = require("crypto"); | |
const Queue = require("bull"); | |
const undoQueueWorkers = new Map(); | |
const { redis: redisConfig } = require("../config"); |
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 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. | |
* |
OlderNewer