const axios = require('axios');
const xml2js = require('xml2js');
const parser = new xml2js.Parser();
const NULL = 0;
const SECOND = 2;
// Ну концепция данной идеи заключается в том, что если появляется новый канал, то мы его просто добавляем во входной массив,
const rssChannels = [
'https://mos.ru/rss',
'https://lenta.ru/rss/news',
];
// Итоговый, агрегационный массив с новостями со всех полученных источников из входного массива rssChannels
const newsFeed = [];
// Подключение к RSS ленте, получаем XML и приобразуем из него в JS объекты, затем добавляем в агрегационный массив newsFeed
const getChannelFeed = url =>
axios.get(url).then(res => {
return parser.parseStringPromise(res.data)
.then(res => newsFeed.push(...res.rss.channel[NULL].item))
.catch(err => console.log('ERROR: Unable to parse received XML'));
})
.catch(err => console.log('ERROR: Unable to establish URL connection'));
// Заполняем выходной массив контентов
const someFoo = rssChannels =>
Promise.all(rssChannels.map(item => getChannelFeed(item)));
someFoo(rssChannels).then(item => console.log(newsFeed));
const net = require('net');
const crypto = require('crypto');
const handshake = `GET / HTTP/1.1
Host: 192.168.43.135:12345
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: file://
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4
Sec-WebSocket-Key: bKdPyn3u98cTfZJSh4TNeQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
`;
const s = net.connect(8080);
s.on('data', d => {
if (/HTTP\/1\.1 101 Switching Protocols/.test(d)) {
s.write(composeFrame('{"type": "handshake"}'));
setTimeout(
() => s.write(composeFrame('{"type":"action", "value":"move"}')),
10000
);
}
});
s.write(handshake);
function composeFrame(text) {
const mask = crypto.randomBytes(4);
return Buffer.from([
0b10000001,
0b10000000 | text.length,
...mask,
...[...Buffer.from(text)].map((e, i) => e ^ mask[i % 4])
]);
}
find /tmp -type f -name "*.png" -exec sh -c 'n={}; [ -f ${n%png}JPG ] && rm -fv $n' \;
this.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response =>
response || fetch(event.request)
).catch(() =>
caches.match('/')
)
);
});
.aggregate([
{$unwind: "$params"},
{$match: {"params.one": true}},
{$project: {
_id: 0,
name: 1,
age: 1,
two: "$params.two",
three: "$params.three"}
}
])
cluster.setupMaster({exec: 'rcon.js'});
const {createServer} = require('http');
const next = require('next');
const port = parseInt(process.env.PORT, 10) || 4000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
const [, category] = req.url.split(/(?<=^\/products\/+)([^\/]+)/);
if (!category)
handle(req, res);
else
app.render(req, res, '/catalog');
}).listen(port, err => {
if (err)
throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});
import React from 'react';
export default class extends React.Component {
static getInitialProps({asPath}) {
const [, category] = asPath.split(/(?<=^\/products\/+)([^\/]+)/);
return {category};
}
render() {
return (
<div>
<h1>Catalog</h1>
<p>{this.props.category}</p>
</div>
);
}
}
<Link href='/catalog' as='/products/some-category'>
<a>Some category</a>
</Link>
const fs = require('fs');
const path = require('path');
async function readDirFiles(dir) {
const filePaths = await fs.promises.readdir(dir, {withFileTypes: true});
return await Promise.all(
filePaths
.filter(e => e.isFile())
.map(async (e) => {
const p = path.join(dir, e.name)
return {
path: p,
content: await fs.promises.readFile(p, {encoding: 'utf8'})
};
})
);
}
readDirFiles('.')
.then(files => {
console.log(files);
})
.catch(err =>
console.error(err)
);
function insert(n, arr) {
let i = 0;
while (n > arr[i]) i++;
arr.splice(i, 0, n);
return arr;
}
const Curl = require('curl-request');
const req = new Curl();
const {auth: {BASIC}, option: {HTTPAUTH, USERNAME, PASSWORD}} = req.libcurl;
const url = 'localhost:8090/rest/api/2/issue';
const user = 'fred';
const password = 'fred';
const headers = ['Content-Type: application/json'];
const data = `{
"fields": {
"project": {
"key": "TEST"
},
"parent": {
"key": "TEST-101"
},
"summary": "Sub-task of TEST-101",
"description": "Don't forget to do this too.",
"issuetype": {
"id": "5"
}
}
}`;
req
.setOpt(HTTPAUTH, BASIC)
.setOpt(USERNAME, user)
.setOpt(PASSWORD, password)
.setHeaders(headers)
.setBody(data)
.post(url)
.then(res => { console.log(res) })
.catch(e => { console.error(e) });