Skip to content

Instantly share code, notes, and snippets.

View Aschen's full-sized avatar
💭
:trollface:

Adrien Maret Aschen

💭
:trollface:
View GitHub Profile
@Aschen
Aschen / README.md
Last active June 23, 2020 04:13
Geofencing precision

Kuzzle Geofencing precision

I have created a geofencing area around the Ram Manohar Lohia Hospital in New Delhi by using geojson.io.

Ram Manohar Lohia Hospital

I added two point, one inside and the other one outside the hospital but very close to geofencing zone limit (~2m).

Then I use Kuzzle realtime engine to subscribe to notification about document entering or exiting the Hospital geofencing area.

@Aschen
Aschen / unique-id.js
Created May 28, 2020 10:26
Generate random unique ID
const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
function uniqueId (size) {
let id = '';
for (let idx = size; idx--;) {
id += CHARSET[(Math.random() * CHARSET.length | 0)];
}
return id;
@Aschen
Aschen / README.md
Last active January 10, 2021 19:47
V8 Promise Benchmarks

V8 Promise Benchmarks

EDIT: 2021-01-10
Fixed here: nodejs/node#34291

EDIT: 2020-07-10
Explanation here: nodejs/node#33384 (comment)

By benchmarking promises against different version of Node.js, I noticed a performance drop in traditional promises (then/catch) between Node.js 10 and Node.js 12.

const contextStore = new Map();
contextStore.set('requestId', uuid());
asyncLocalStorage.run(contextStore, async () => {
// entering asynchronous context
});
const log = message => {
const requestId = asyncLocalStorage.getStore();
if (requestId) {
console.log(`[${requestId}] ${message}`);
}
else {
console.log(message);
}
};
const { AsyncLocalStorage } = require('async_hooks');
const asyncLocalStorage = new AsyncLocalStorage();
app.get('/', (request, response) => {
const requestId = uuid();
asyncLocalStorage.run(requestId, async () => {
// entering asynchronous context
log('Start processing');
await emailService.notify(request.body.emails);
class EmailService {
constructor (log) {
this.log = log;
}
async notify (emails, requestId) {
for (const email of emails) {
this.log(`[${requestId}] Send email: ${email}`);
sendGrid.send(email);
}
const app = express();
const log = message => console.log(message);
const emailService = new EmailService(logger);
app.get('/', (request, response) => {
const requestId = uuid();
log(`[${requestId}] Start processing`);
await emailService.notify(request.body.emails, requestId);
@Aschen
Aschen / README.md
Last active May 3, 2023 11:23
Benchmarking AsyncLocalStorage

What is the overhead of AsyncLocalStorage?

Run the benchmark:

$ npm i benchmark

# Run the AsyncLocalStorage benchmark
$ node async-local-storage.js ASL
ASL x 15,551 ops/sec ±3.30% (79 runs sampled)
@Aschen
Aschen / int32_vs_float64.cr
Created March 29, 2020 04:45
Int32 vs Float64 performances in Crystal
# https://stackoverflow.com/questions/60910274/int32-vs-float64-performances-in-crystal
require "benchmark"
def percentage_diff(number_a, number_b)
small_number = (number_a > number_b) ? number_b : number_a
big_number = (number_a < number_b) ? number_b : number_a
(big_number - small_number) / small_number
end