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 / class.ts
Created January 22, 2024 17:24
Method vs member holding a function
class Foobar {
private name = 'foobar'
getName = () => {
return this.name
}
}
class Barfoo {
private name = 'barfoor'
@Aschen
Aschen / agent-llm.js
Created November 8, 2023 19:45
Assistant OpenAI benchmark
function createTask (req, res) {
const newTask = req.body;
verifyTask(newTask);
const savedTask = database.addTask(newTask);
res.status(201).send(`Task ${savedTask.metadata.id} saved successfully`);
}
function addTask(newTask) {
const tasks = readTasksFromFile();
const taskWithId = { ...newTask, metadata: { id: generateId() } };
@Aschen
Aschen / start.sh
Created October 15, 2023 09:00
WebHook development: HTTP echo server
node -e "const h = require('http');const s = h.createServer();const l = console.log;s.on('request', (rq, rs) => {let b = [];rq.on('data', (c) => {b.push(c);}).on('end', () => {b = Buffer.concat(b).toString();l('==== '+rq.method+' '+rq.url);l('> Headers');l(rq.headers);l('> Body');l(b);rs.end();});}).listen(8000);"
@Aschen
Aschen / README.md
Created October 3, 2023 09:43
Return await vs return promise

Result:

Error: whoops
    at last (/Users/adrien/projects/didask/odc/test.ts:43:9)
    at middle (/Users/adrien/projects/didask/odc/test.ts:47:16)
    at first (/Users/adrien/projects/didask/odc/test.ts:51:16)
    at run (/Users/adrien/projects/didask/odc/test.ts:56:11)
    at Object.<anonymous> (/Users/adrien/projects/didask/odc/test.ts:68:1)
 at Module._compile (node:internal/modules/cjs/loader:1256:14)
@Aschen
Aschen / README.md
Last active July 30, 2023 12:48
Performance differences for classification (BART) between Transformers.js and Transformers (Python)

Performance differences for classification (BART) between Transformers.js and Transformers (Python)

This is a GIST for this issue in Transformer.js repository

Trying to classify the following texts as street address:

  • '1 rue de la paix',
  • 'Karlstraße 12, 80333 Munich, DE',
  • 'Startups da América Latina demonstraram capacidade de gerar valor econômico diz fundo alemão',
  • "But what if one day, you come up with a great idea to combine those, for instance to use some Python libraries in your application, but you just do not have any idea how to integrate it with your Node.js application. Of course you can always build API on top of Python backend(Flack, etc), but in that case you need to build, host and manage one more application, when you just need to run a single Python script. That's why I want to give you step by step instructions on how to achieve this.\n",
@Aschen
Aschen / README.md
Last active October 10, 2022 18:49
Proxy Benchmark

Proxy Benchmark

Install npm i benchmark

Run:

$ node proxy.js  
object x 220,987,620 ops/sec ±0.55% (97 runs sampled)
proxy x 2,553,992 ops/sec ±0.47% (92 runs sampled)
@Aschen
Aschen / README.md
Created August 30, 2022 07:50
Kuzzle JS SDK: Recover from backend failure

Expected output when restarting Kuzzle backend:

node recover.js

connected
logged
Kuzzle time: 1661845705110
disconnected
reconnected
@Aschen
Aschen / README.md
Created July 29, 2022 15:07
Copy labels from one Github repository to another

Copy labels from one Github repository to another

Install dependencies npm i @octokit/rest

Generate a Github Personnal Token (starts with ghp_) and insert it in the script.

Choose the source repository and insert it in the script (e.g. kuzzleio/kuzzle)

Run the script: node copy-labels.js kuzzleio/koncorde

@Aschen
Aschen / README.md
Created July 18, 2022 17:07
For loop with `var` vs `let`

For loop with var vs let

Using a var instead of a let in a for loop was a game changer with Node.js 6 but now it's merely the same performances.

for (var i = 0; i < 10000; i++) {
  // ...
}

for (let i = 0; i < 10000; i++) {
@Aschen
Aschen / README.md
Created May 11, 2022 17:39
Call function with simple argument vs object argument

npm i benchmark

results

simple function call x 962,129 ops/sec ±2.62% (79 runs sampled)
object function call x 900,959 ops/sec ±2.13% (89 runs sampled)
Fastest is simple function call

Around 0.1 ms for 1000 calls