This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const files = [/* file names here */]; | |
const limit = 100; | |
async function main() { | |
const workers = []; | |
while(workers.length <= limit) { | |
const w = worker(files); | |
workers.push(w); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |