function pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
pad("3", 3); // => "003"
pad("123", 3); // => "123"
pad("1234", 3); // => "1234"
var test = "MR 2";
var parts = test.split(" ");
parts[1] = pad(parts[1], 3);
parts.join(" "); // => "MR 002"
Record: -d duration
arecord -d 5 test-mic.wav
Play:
aplay test-mic.wav
Paging works by creating an area on your hard drive and using it for extra memory, this memory is much slower than normal memory however much more of it is available.
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1
If you need more than 1024 then change that to something higher.
To enable it by default after reboot, add this line to /etc/fstab:
/var/swap.1 swap swap defaults 0 0
find . -type f -exec chmod 644 {} +
find . -type d -exec chmod 744 {} +
function memoryUsage(cb) {
var spawn, proc, str, lines, i, total, free, used;
spawn = require('child_process').spawn;
proc = spawn('free', ['-m']);
proc.stdout.setEncoding('utf8');
proc.stdout.on('data', function (data) {
str = data.toString();
lines = str.split(/\n/g);
for (i = 0; i < lines.length; i++) {
lines[i] = lines[i].split(/\s+/);
}
total = parseInt(lines[1][1]);
free = parseInt(lines[2][2]);
used = parseInt(lines[2][3]);
});
proc.on('close', function (code) {
cb({
unit: "megabytes",
total: total,
free: free,
used: used,
percent: {
free: parseInt((free / total * 100))
}
});
});
}
memoryUsage(function(memmory) {
console.log(memmory);
});