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 / 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 / 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 / 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 / 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 / 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 / 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 / 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-generator-example-1.js
Created May 20, 2018 14:11
Async Generator, Async Iterator in NodeJS v10, medium
const arr = range(4, 8);
arr.next(); // Promise
(async () => {
console.log(await arr.next()); // {value: 5, done: false}
})();
(async () => {
console.log(await arr.next()); // {value: 6, done: false}
})();
@nairihar
nairihar / async-generator.js
Created May 20, 2018 14:09
Async Generator, Async Iterator in NodeJS v10, medium
async function* range(start, stop) {
for (let i = start; i <= stop; i++) {
yield i;
}
}
@nairihar
nairihar / for-await-of.js
Last active May 20, 2018 14:40
for-await-of, Async Iterator in NodeJS v10, medium
function myPromise(t) {
return new Promise((r) => {
setTimeout(() => {
r(t);
}, t);
});
}
const arr = [myPromise(2000), myPromise(500), myPromise(400)]; // iterable object