Skip to content

Instantly share code, notes, and snippets.

@Spuffynism
Spuffynism / create_vhost.sh
Created May 21, 2018 22:48
Creates a virtual host
if [[ $# -eq 0 ]] ; then
echo 'You must specify a valid virtual host name'
exit 0
fi
vhost=$1
export vhost
sudo mkdir -p /var/www/"$vhost"/public_html
sudo chmod -R 777 /var/www/"$vhost"
@Spuffynism
Spuffynism / delete_vhost.sh
Created May 21, 2018 22:52
Deletes a virtual host
if [[ $# -eq 0 ]] ; then
echo 'You must specify a valid virtual host name'
exit 0
fi
vhost=$1
export vhost
sudo rm -rf /var/www/"$vhost"
sudo a2dissite "$vhost".conf
@Spuffynism
Spuffynism / sort_spotify_tracks_by_listening_count.js
Last active August 24, 2022 06:10
Takes a streaming history spotify file and sorts the tracks by listening count
let fs = require('fs');
let path = process.cwd();
console.log('looking for StreamingHistory.json file in ' + path + '\\data\\');
let buffer = {};
try {
buffer = fs.readFileSync(path + "\\data\\StreamingHistory.json");
} catch (e) {
/*
Variations of https://medium.com/@d0nut/why-building-a-sandbox-in-pure-javascript-is-a-fools-errand-d425b77b2899
jailbreaking example.
*/
var flag = "I'm the flag!";
function jail(code) {
// quick string escape for inner strings
code = code.replace(/["'`\\]/g, function(v){ return `\\${v}`});
@Spuffynism
Spuffynism / squeeze.js
Last active July 8, 2018 00:05
Squeeze utf-8 characters in half their space
let squeeze = s => s.replace(/../g,c=>String.fromCharCode(c[a='charCodeAt']()|c[a](1)<<7));
let unsqueeze = s => s.replace(/./g,c=>String.fromCharCode((c=c.charCodeAt())&127,c>>7));
console.log(unsqueeze("㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ᝸㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵ᤬ᠰᶩ") ===
"for(c.width|=i=9;i--;)x.fillRect(400+i*100+S(t)*300,400,50,200);");
console.log(squeeze("for(c.width|=i=9;i--;)x.fillRect(400+i*100+S(t)*300,400,50,200);") ===
"㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ᝸㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵ᤬ᠰᶩ");
console.log("㟦ᑲᝣ㓷㩤㹨㒽Ჽ㒻ᚭᒻ᝸㓦㙬㋒㩣ᨨᠰ㒫ᢪᠰ⦫㨨ᔩᠳᘰᠴᘰᠵ᤬ᠰᶩ".length === 32);
@Spuffynism
Spuffynism / sequence.js
Created July 1, 2018 04:06
Recursive sequence emulating functional languages' "freeze" functions
function* sequence(x) {
yield x;
yield * sequence(x + 1);
}
@Spuffynism
Spuffynism / codegolfing-generators.js
Last active July 7, 2018 23:50
Codegolfing generators
// recursive infinite generator
p=function*a(x){yield x;yield*a(x+1)}(0)
o={*a(x){yield x;yield*this.a(x+1)}}.a(0)
// using iterators
q=(x=>({next:_=>({value:x++})}))(0)
@Spuffynism
Spuffynism / explain-this.js
Created July 18, 2018 02:04
explain this
// Collection of weird JS snippets
// taking advantage of non-utf chars
thіs.x = 'a'
this.x // error
// taking advantage of regex syntax
/(\/)/gimuy.exec`\/`[-[~[]]]
@Spuffynism
Spuffynism / caesar_cypher.js
Last active November 27, 2018 03:38
Caesar Cypher
e=(m,a,b)=>m.replace(/./g,c=>String.fromCharCode(((c.charCodeAt()-65)*a+b)%26+65))
d=(m,a,b)=>m.replace(/./g,c=>String.fromCharCode(a*(c.charCodeAt()-39-b)%26+65))
`0 7→ 20, 1 7→ 13, 2 7→ 21, 3 7→ 0, 4 7→ 1, 5 7→ 2, 6 7→ 3, 7 7→ 4, 8 7→ 5,
9 7→ 6, 10 7→ 7, 11 7→ 8, 12 7→ 9, 13 7→ 10, 14 7→ 11, 15 7→ 12, 16 7→ 14,
17 7→ 15, 18 7→ 16, 19 7→ 17, 20 7→ 18, 21 7→ 19, 22 7→ 22,
23 7→ 23, 24 7→ 24, 25 7→ 25`.split(',')
.map(v =>
v.replace('7→','')
.trim()
.split(' '))
.map(v=>({[v[1]]:v[0]}))
.reduce((v, acc) => Object.assign(acc,v),{});