Skip to content

Instantly share code, notes, and snippets.

View ileathan's full-sized avatar

Spinelli Valentinuzzi ileathan

View GitHub Profile
@ileathan
ileathan / remote-sudo.sh
Last active January 29, 2018 00:33
Run sudo command on remote machine non-interactively
#!/bin/bash
# USAGE:
# ./remote-sudo.sh password hostname command
HOST=$2;
PASSWORD=$1;
COMMAND="${@:3}"
ssh -T $HOST "echo $PASSWORD | sudo -S su -c \"$COMMAND\""
@ileathan
ileathan / base-x encoder gist
Last active January 29, 2018 00:39
Continually mod and map.
encode = (n, a) => {
var r = [];
do {
n = (n - (r[r.length] = n % a.length)) / a.length
} while(n);
return r.map(n=>a[n]).reverse().join('')
};
encode(4095, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')
// Outputs "//"
true|0**0 === 1; // true
NaN|0**0 === 1; // true
false|0**0 === 1; // true
// ...
add=(_=>n=>_+=n)(0)
add(5) // => 5
add(10) // => 15
add(7) // -> 22