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 / gist:78e9e875df646698243affe1870dda58
Created March 29, 2017 20:14
Android, Java: mix 2 PCM audio files
private void mixSound() throws IOException {
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, 44100, AudioTrack.MODE_STREAM);
InputStream in1=getResources().openRawResource(R.raw.track1);
InputStream in2=getResources().openRawResource(R.raw.track2);
byte[] music1 = null;
music1= new byte[in1.available()];
music1=convertStreamToByteArray(in1);
in1.close();
@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.)