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
import { subscriber } from '@private-rabbitmq-wrapper'; | |
import { EventEmitter, once } from 'events'; | |
import { ConsumeMessage, Replies } from 'amqplib'; | |
interface Options { | |
exchange: string; | |
eventName: string; | |
queueName: string; | |
forwardedEventName: (_: ConsumeMessage) => string; | |
} |
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
user@hostname:~ | |
$ docker images | |
REPOSITORY TAG IMAGE ID CREATED SIZE | |
dpage/pgadmin4 latest 048c641d6e64 4 weeks ago 244MB | |
debian buster 0d587dfbc4f4 6 weeks ago 114MB | |
golang 1.16-alpine 14ee78639386 7 weeks ago 301MB | |
alpine latest 49f356fa4513 7 weeks ago 5.61MB | |
postgres 13 88590756b124 7 weeks ago 314MB | |
postgres latest 88590756b124 7 weeks ago 314MB | |
golang 1.16 64bd1a7b99b7 8 weeks ago 862MB |
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
package main_test | |
import ( | |
"testing" | |
"testing/quick" | |
"unsafe" | |
) | |
func all(xs []*int, f func(x *int) bool) (result bool) { | |
result = true |
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
open Core | |
module type Caesar_intf = sig | |
val decrypt: string -> int -> string | |
val encrypt: string -> int -> string | |
end | |
module Caesar: Caesar_intf = struct | |
let transform_alpha scale c = | |
if not (Char.is_alpha c) then c else |
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
import sys | |
def normalize(c: str): | |
""" | |
Given c, a string of only one character, normalize returns the | |
character position of c in the English alphabet, with 'a' | 'A' = 0 | |
and 'z' | 'Z' = 25, and an indication of whether c was uppercase. | |
Only alphabetic ASCII characters are transformed. | |
""" | |
if not (c.isascii() and c.isalpha()): |
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 extractMongoId(document) { | |
const doc = document.toObject ? document.toObject() : document; | |
for (const [key, value] of Object.entries(doc)) { | |
if (value instanceof ObjectID) { | |
delete doc[key]; | |
doc[key] = value.toHexString(); | |
} else if (value instanceof Object) { | |
doc[key] = extractMongoId(value); | |
} | |
if (Array.isArray(value)) { |
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
// file resource-controllers.js | |
const { makeWorker, cancelJob } = require("./undo-queue"); | |
async function deleteResource (/* parameters */) { | |
// code to delete the resource | |
} | |
const scheduleResourceDeletion = makeWorker(deleteResource); | |
exports.delete = function (req, res, next) { |
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. | |
* |
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
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(); |
NewerOlder