Skip to content

Instantly share code, notes, and snippets.

View danielecr's full-sized avatar
🐢
stay quite

Daniele Cruciani danielecr

🐢
stay quite
View GitHub Profile
@danielecr
danielecr / wait-prompt.js
Created May 11, 2022 08:07
await for the prompt question
const readline = require('readline');
const waitPrompt = (line) => new Promise((resolve,reject) => {
const handle = (msg) => (err) => {
//console.log(msg, err);
reject(err);
}
const d = require('domain').create();
d.on('error', handle("ERROR"));
@danielecr
danielecr / get-all-paths.js
Created May 10, 2022 16:20
find all path in a digraph
// find list of all paths in a digraph defined by a set of edges
// create a list of candidates.
// repeat until is not stable:
// for each edge: try to extends the candidate: at the end, at the begin
// after first turn, also split paths if necessary
// if a whole edge turn is stable, break the loop.
// Complexity: enough
let edges = [];
@danielecr
danielecr / src_data.txt
Created December 11, 2019 16:55
Some code to show events in stream
example text data to copy from
execute
> node stream-to-target.spec.js
to read:
"""
read stream end
write stream finish ./tgt_data.txt
read stream close
@danielecr
danielecr / problem1.txt.md
Created August 29, 2019 19:55
eventloop based async programming patterns

There are patterns for solving async tasks. Not just promise vs callback. Real problems and real patterns

Problem example 1.

Send messages to a service that give reply async, store data into an array of promises, solve all promises at the end. Additional constraint: the number of message that could be sent to the service is limited, and the only way to test if the limit is reached is to catch an exception on failed sent.

i.e.

@danielecr
danielecr / testTimer-wrong.php
Created August 29, 2019 13:33
tricky timer in reactphp
<?php
require_once 'vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$context = new React\ZMQ\Context($loop);
$timer = $loop->addPeriodicTimer(20, function() use($timer) {
global $loop;
echo "is executed\n";
@danielecr
danielecr / zmq-client.js
Created July 31, 2019 19:31
Compare node with reactphp
const zmq = require('zeromq-stable');
const messageToJson = (request) => {
try {
return JSON.parse(request.toString());
} catch (err) {
return { error: {msg: 'error while parsing', detail: err.toString}}
}
}