Skip to content

Instantly share code, notes, and snippets.

@mpuz
mpuz / puppdep.sh
Created December 8, 2023 10:02
puppeteer dependencies
sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
@mpuz
mpuz / promiseforof.js
Created May 10, 2022 20:51
Promisify for of loo[
function doSomethingAsync(value) {
return new Promise((resolve) => {
setTimeout(() => {
console.log("Resolving " + value);
resolve(value);
}, Math.floor(Math.random() * 1000));
});
}
function test() {
@mpuz
mpuz / duplicates.js
Created March 19, 2022 13:45
remove dulplicates in the array of objects by one of params
const filteredArr = arr.reduce((acc, current) => {
const x = acc.find(item => item.id === current.id);
if (!x) {
return acc.concat([current]);
} else {
return acc;
}
}, []);
echo "export PATH=$PATH:$(npm get prefix)/bin" >> ~/.bashrc
@mpuz
mpuz / fixnode.txt
Created October 12, 2021 11:19
fix node js permissions
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
@mpuz
mpuz / moveup.sh
Created September 30, 2021 17:08
moves files from subfolders up
find . -mindepth 2 -type f -print -exec mv --backup=numbered {} . \;
@mpuz
mpuz / checkinternetspeedfromcli.txt
Last active April 3, 2021 18:50
check internet speed from cli
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
@mpuz
mpuz / copysshkeys.sh
Created April 1, 2020 20:45
copying SSH keys to server
cat ~/.ssh/id_rsa.pub | ssh user@222.22.22.2 "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
@mpuz
mpuz / hashcode.js
Created March 18, 2020 14:50
JavaScript implementation of hashcode
/**
* Returns a hash code for a string.
* (Compatible to Java's String.hashCode())
*
* The hash code for a string object is computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using number arithmetic, where s[i] is the i th character
* of the given string, n is the length of the string,
* and ^ indicates exponentiation.
* (The hash value of the empty string is zero.)
The for–in loop is for looping over object properties.
The for–of loop is for looping over data—like the values in an array.