Skip to content

Instantly share code, notes, and snippets.

View nairihar's full-sized avatar
😎
Always busy

Nairi Harutyunyan nairihar

😎
Always busy
View GitHub Profile
@nairihar
nairihar / async-generator-example-2.js
Created May 20, 2018 14:15
Async Generator, Async Iterator in NodeJS v10, medium
const arr1 = range(1, 3);
(async () => {
for await (let n of arr1) {
console.log(n);
}
})();
// 1, 2, 3
@nairihar
nairihar / async-iterator-fs-node.js
Created May 20, 2018 14:47
AsyncIteration using FS, Async Iterator in NodeJS v10, medium
const express = require('express');
const fs = require('fs');
const app = express();
app.get('/', async (req, res) => {
const stream = fs.createReadStream('file_name', {
highWaterMark: 5
});
for await (const chunk of stream) {
@nairihar
nairihar / q.js
Last active May 26, 2018 17:19
Optym internship 1.2, Stack and Q examples
let myQ = Q();
myQ.push(1);
myQ.push(2);
myQ.push(3);
console.log(myQ.pop()); // 1
console.log(myQ.pop()); // 2
console.log(myQ.pop()); // 3
@nairihar
nairihar / description
Created May 29, 2018 12:44
Optym Internship, lesson 3, game description and solutions
Find the number of ways to express n as sum of some (at least two) consecutive positive integers.
Example
For n = 9, the output should be
isSumOfConsecutive2(n) = 2.
There are two ways to represent n = 9: 2 + 3 + 4 = 9 and 4 + 5 = 9.
For n = 8, the output should be
@nairihar
nairihar / server_1.js
Last active June 21, 2018 13:22
NodeJS Health Check and Overload Protection, medium
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.end(`Hello PID: ${process.pid}`);
});
app.get('/check', (req, res) => {
console.log('Health Check Request');
res.status(200).end();
@nairihar
nairihar / server_2.js
Last active June 21, 2018 11:12
NodeJS Health Check and Overload Protection, medium
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.end(`Hello PID: ${process.pid}`);
});
let status = 200;
setTimeout(() => {
status = 503;
@nairihar
nairihar / haproxy.cfg
Last active June 22, 2018 08:18
NodeJS Health Check and Overload Protection, medium
global
log 127.0.0.1 local0 notice
user haproxy
group haproxy
defaults
log global
mode http
option httplog
@nairihar
nairihar / set_example_1.js
Last active June 22, 2018 11:53
JavaScript series, part 1, Set, medium
const mySetFromArray = new Set([1, 2, 3]);
@nairihar
nairihar / set_example_2.js
Last active June 22, 2018 11:53
JavaScript series, part 1, Set, medium
const mySetFromString = new Set('hello');
@nairihar
nairihar / set_speed_test_1.js
Last active June 23, 2018 18:39
JavaScript series, part 1, Set, medium
console.time('Set test');
const set = new Set();
const count = 10;
for (let i = 0; i < count; i++) {
set.add(i);
}