Skip to content

Instantly share code, notes, and snippets.

View kvasdopil's full-sized avatar

Alexey Guskov kvasdopil

  • Instabee
  • Stockholm, Sweden
View GitHub Profile
async function processStream(stream)
{
while(let data = await stream.read())
{
// process data
}
}
db.on('end', () => db.close());
await Promise.all([1, 2, 3].map(i =>
@kvasdopil
kvasdopil / sdgfdsg.py
Last active February 14, 2017 13:47 — forked from anonymous/sdgfdsg
import os, time, re
import paramiko
from zbxsend import Metric, send_to_zabbix
#Параметры для подключения по ssh
username='root' # ssh: login
ssh_key='/root/.ssh/id_dsa.pub' # ssh: password
port=22 # ssh: port
back_servs = [ea1-wal-backups, ea1-wal-backup2, ea1-wal-backup3, ea1-wal-backup4]
const files = [/* file names here */];
const limit = 100;
async function main() {
const workers = [];
while(workers.length <= limit) {
const w = worker(files);
workers.push(w);
}
export const findFile = (node, fn, pathToFile = '') => {
const filePath = path.join(pathToFile, node.name);
if (node.type === 'directory') {
return node.children
.map(element => findFile(element, fn, filePath))
.reduce((res, found) => [...res, ...found], []);
}
if (fn(node)) {
return [filePath];
}
@kvasdopil
kvasdopil / justDuIt.js
Last active April 16, 2018 13:43 — forked from tuor4eg/justDuIt
export const countSize = (node) => {
reduce((size, element) => {
if (element.type === 'file') {
return (size + element.meta.size);
}
return size;
}, node, 0);
export default (tree) => {
const duIt = tree
function concat(args, func, cb) {
const results = [];
const errors = [];
args.forEach(arg => func(arg, (err, files) => {
if (err) {
errors.push(err);
} else {
results.push(files);
}
function filter(args, func, cb) {
const results = args.map(i => null);
const count = 0;
const error = null;
args.map((item, j) =>
func(item, (err, res) => {
count++;
if (err) {
error = err;
} else {
$ node
> const url = require('url');
undefined
> const a = url.parse('http://amazon.com/search?page=10&per=5');
undefined
> a
Url {
protocol: 'http:',
slashes: true,
auth: null,
export default (backendUrl, currentUrl) => {
return new Promise((resolve, reject) => {
get(backendUrl)
.then(response => {
if (response.status !== 200) {
reject(new Error(response.status));
return;
}
const parseJs = JSON.parse(response.data);
const checkLoad = Promise.all(parseJs.map(element => {
@kvasdopil
kvasdopil / server.js
Last active July 16, 2018 14:40 — forked from tuor4eg/server.js
const readFileAsync = file => new Promise((resolve, reject) => {
fs.readFile(file, (err, data) => err ? reject(err) : resolve(data));
});
const records = async (req, res) => {
await readFileAsync('phonebook.txt');
const count = readBook.toString().split('\n').length - 1;
const str = `Welcome to The Phonebook\nRecords count: ${count}`;
res.write(str);
};