Skip to content

Instantly share code, notes, and snippets.

View llimacruz's full-sized avatar

Leonardo de Lima Cruz llimacruz

View GitHub Profile
@llimacruz
llimacruz / forJS.js
Created March 26, 2017 15:10
Assinc for in js
'use strict';
// does not work
for (var i = 1; i <5; i++) {
setTimeout(function() {
console.log('i: ' + i);
}, i * 1000);
}
// work
@llimacruz
llimacruz / async queue whilst
Created May 31, 2017 01:07
Exemplo de utilização de async.queue mais async.whilst
var async = require('async')
var tempoEsperaSemRegistro = 20 * 1000
var quantidadeParalela = 10
var quantidadeFila = 100
var count = 0;
var cb;
var encheFila = (callback) => {
const simuladorDeFuncaoAssincrona = (index, ms) => new Promise(resolve => {
setTimeout(() => {
console.log('executando funcao assincrona', index)
resolve()
}, ms)
});
// [1, 2, 3].forEach(async (num) => {
// await waitFor(500);
// console.log(num);
@llimacruz
llimacruz / js-literal-versus-parsed-json
Created June 29, 2019 11:04
Comparar a criação de um objeto literal com um parse de json
const runTest = () => {
const n = 10000000;
// literal
let init = new Date();
for (let i = 1; i <= n; i++) {
const data = { foo: 42, bar: 1337 };
}
let end = new Date();
console.log('literal: ' + (end - init));
@llimacruz
llimacruz / consumer-by-topic.js
Created January 9, 2020 14:34
Streams - branch
const kafka = require('kafka-node');
const ConsumerGroup = kafka.ConsumerGroup;
const topic = process.argv[2];
console.log('topic name:', topic);
const consumer = new ConsumerGroup(
{ kafkaHost: 'localhost:9092', groupId: 'node-consumer'},
topic
)