const SSH = require('simple-ssh');
const hosts = ['192.168.10.1', '192.168.20.1',];
async function processIPs(ipArr) {
for (ip of hosts) {
//console.log(ip);
const ssh = new SSH({
host: ip,
port: '22',
user: 'root',
pass: 'password'
});
const pr = new Promise((res, rej) => {
ssh
.exec('cat /proc/uptime', {
out: function(stdout) {
res(stdout);
}
})
.start();
});
const result = await pr;
console.log("ip: %s, result: %s", ip, result);
}
});
processIPs (hosts);
console.log("Done");
$content
записано имя свойства. См. variable variables.class X {
private $a = "A";
private $b = "B";
public function test($content) {
echo $this->$content . PHP_EOL;
}
}
$x = new X();
$x->test("a"); // A
$x->test("b"); // B
let user = {
name: 'Василий',
get name2() {
return this.name;
}
};
user.name2 // Василий
poll_id
– id опроса (там сквозная нумерация, можно придумать любой), и owner_id
– id владельца, создавшего опрос.$sum = array_sum($a);
$rnd = rand() / getrandmax(); // от 0 до 1
$runningSum = 0;
foreach($a as $k => $v) {
$runningSum += $v / $sum;
if ($runningSum >= $rnd) {
$key = $k;
break;
}
}
if (!$key) $key = $k;
echo "Выпало: " . $key . PHP_EOL;
ffmpeg -i video.mp4 -i watermark.png -filter_complex "overlay=10:10" result.mp4
<div v-bind:class="{ active: isActive }"></div>
isActive
, класс active
добавится/уберется.function monthly(a, b, n) {
const result = a * b / 12;
console.log("%f * %f / 12 = %f", a, b, result);
if (n) return monthly(a + result, b, n - 1);
else return result;
}
monthly(1e6, 0.15, 12);
1000000.000000 * 0.150000 / 12 = 12500.000000
1012500.000000 * 0.150000 / 12 = 12656.250000
1025156.250000 * 0.150000 / 12 = 12814.453125
1037970.703125 * 0.150000 / 12 = 12974.633789
1050945.336914 * 0.150000 / 12 = 13136.816711
1064082.153625 * 0.150000 / 12 = 13301.026920
1077383.180546 * 0.150000 / 12 = 13467.289757
1090850.470303 * 0.150000 / 12 = 13635.630879
1104486.101181 * 0.150000 / 12 = 13806.076265
1118292.177446 * 0.150000 / 12 = 13978.652218
1132270.829664 * 0.150000 / 12 = 14153.385371
1146424.215035 * 0.150000 / 12 = 14330.302688
1160754.517723 * 0.150000 / 12 = 14509.431472
eval(JSON.stringify(array).replace(/[^\d]+/g, '+') + '0') // 31
const a = [1, 2, [3, 4, [[5, 6], 7], 8]];
// Вжух! и получится строка:
"+1+2+3+4+5+6+7+8+"
timeout
Type: Number
Set a timeout (in milliseconds) for the request. A value of 0 means there will be no timeout. This will override any global timeout set with $.ajaxSetup(). The timeout period starts at the point the $.ajax call is made; if several other requests are in progress and the browser has no connections available, it is possible for a request to time out before it can be sent. In jQuery 1.4.x and below, the XMLHttpRequest object will be in an invalid state if the request times out; accessing any object members may throw an exception. In Firefox 3.0+ only, script and JSONP requests cannot be cancelled by a timeout; the script will run even if it arrives after the timeout period.
str[i] = "x"
Так можно только читать.function reverse(str) {
var i, len = str.length, result = "";
for (i = len - 1; i >= 0; i--) result += str[i];
return result;
}
function getWithImages(result) {
return new Promise((res, rej) => {
const elPromises = [];
for (let key in result) {
if (!result.hasOwnProperty(key)) continue;
const element = result[key];
element.introtext = h2p(element.introtext);
element.fulltext = h2p(element.fulltext);
elPromises.push(
clientGI.search(element.title)
.then(images => {
element.images = images.map(image => [image.url, image.thumbnail]);
});
);
}
Promise.all(elPromises).then(function() {
// все готовы
res(result);
});
});
}
const gotImagesPromise = getWithImages(results[0]);
/**
* Разбивает строку на три части: цифры, две буквы, две буквы.
* Возвращает либо массив из трех элементов,
* либо undefined
*/
function getParts(str) {
const re = /^(\d+)(\S{2})(\S{2})$/;
const match = str.match(re);
if (match) return match.slice(1);
}
getParts("5дмсм") // ["5", "дм", "см"]
YX| 0 1 2 3 4
--|-----------
0 | 0 1 0 0 1
1 | 1 1 0 1 1
2 | 1 0 1 1 0
3 | 0 1 1 0 0
4 | 0 0 1 0 0
[(1,0), (0,1), (1,1), (0,2)],
[(4,0), (3,1), (4,1), (2,2), (3,2), (1,3), (2,3), (2,4)]
>> 1, 2, 3, 4, 5;
<– 5
undefined
.console.log()
. function camelCase(str) {
return str
.trim()
.split(' ')
.map((w, i, a) => {
if (i === 0) return w.toLowerCase();
return w.substr(0, 1).toUpperCase() + w.substr(1).toLowerCase();
})
.join('')
}
function test() {
const testIn = ['Good Day', 'good night', 'Good Evening', 'Sleep', 'Go'];
const testOut = ['goodDay', 'goodNight', 'goodEvening', 'sleep', 'Go'];
for (let i = 0; i < testIn.length; i++) {
const input = testIn[i];
const output = camelCase(input);
if (testOut[i] === output) console.log("Test passed: %s => %s", input, output);
else console.error("Test failed: %s => %s", input, output);
}
}
test();