Skip to content

Instantly share code, notes, and snippets.

View rodrigograca31's full-sized avatar
πŸ‘¨β€πŸ’»
Professional πŸ› solver

Rodrigo GraΓ§a rodrigograca31

πŸ‘¨β€πŸ’»
Professional πŸ› solver
View GitHub Profile
@rodrigograca31
rodrigograca31 / array-shuffle.js
Created August 12, 2020 11:52
Shuffles array in place. ES6 version
/**
* Shuffles array in place. ES6 version
* @param {Array} a items An array containing the items.
* https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array
*/
shuffle(a: Array<any>) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
@rodrigograca31
rodrigograca31 / events_to_promise.js
Last active October 11, 2020 21:33
Turn Events into Promises in JavaScript
const events = [download, download2];
const promises = events.map((event) => {
return new Promise((resolve) => {
event.on("end", (paths) => {
resolve(paths);
});
});
});
Promise.all(promises).then((result) => {});
@rodrigograca31
rodrigograca31 / latest-node.sh
Created December 7, 2020 18:57
Latest NodeJS version on Raspberry PI 0
export NODE_VER=14.15.1
if ! node --version | grep -q ${NODE_VER}; then
(cat /proc/cpuinfo | grep -q "Pi Zero") && if [ ! -d node-v${NODE_VER}-linux-armv6l ]; then
echo "Installing nodejs ${NODE_VER} for armv6 from unofficial builds..."
curl -O https://unofficial-builds.nodejs.org/download/release/v${NODE_VER}/node-v${NODE_VER}-linux-armv6l.tar.xz
tar -xf node-v${NODE_VER}-linux-armv6l.tar.xz
fi
echo "Adding node to the PATH"
PATH=$(pwd)/node-v${NODE_VER}-linux-armv6l/bin:${PATH}
fi