Skip to content

Instantly share code, notes, and snippets.

@alanmquach
alanmquach / SF49ers.sh
Created September 16, 2013 21:06
Colored (red/white) SF 49ers logo used in my bash .profile to print a 49ers logo in new terminal windows. Best used in widescreen terminal windows with a black background and default gold text.
echo " "
echo " ___,,.................,,___ "
echo " ,.--'''"$'\e[1;31m'"_,.---'''''''''''''''''---.,_"$'\e[0m'"'''--., "
echo " ,.-''"$'\e[1;31m'"_,.--''"$'\e[1;31m'" "$'\e[1;31m'"''--.,_"$'\e[0m'"''-., "
echo " ,.-'"$'\e[1;31m'",.-'' "$'\e[1;37m'",..--------..,,-----. "$'\e[1;31m'"''-.,"$'\e[0m'"'-., "
echo " ,' "$'\e[1;31m'",-' "$'\e[1;37m'",.-'' _.....,, : "$'\e[1;31m'"'-, "$'\e[0m'"', "
echo " ,' "$'\e[1;31m'". "$'\e[1;37m'".' ( ''-._, : "$'\e[1;31m'". "$'\e[0m'"', "
echo " ,' "$'\e[1;31m'".' "$'\e[1;37m'": ''------...._ '''' "$'\e[1;31m'"'. "$'
@alanmquach
alanmquach / SSHKeyer
Created July 17, 2014 06:44
Expect wrapped ssh command to put public key onto a server
/usr/bin/expect -c "set timeout 60; spawn ssh ${SSH_OPTS} ${USERID}@${HOST} \"mkdir -p ~/.ssh && echo \\\"`cat ~/.ssh/id_rsa.pub`\\\" >> ~/.ssh/authorized_keys\"; expect \"*?assword:*\"; send -- \"${PASSWD}\r\"; expect eof"
@alanmquach
alanmquach / plumber.js
Last active August 29, 2015 14:12
Process unix streams with a node script
#!/usr/bin/env node
// $ echo "madam im adam" | ./plumber.js
require('readline').createInterface({
input: process.stdin,
terminal: false
}).on('line', function(line){
process.stdout.write(line.split("").reverse().join("") + '\n');
});
@alanmquach
alanmquach / RxZipper.js
Last active November 25, 2015 12:59
RxJS equivalent of async.parallel
var Rx = require('rx');
var zipper = function () {
// Turning arguments from an object into an actual array so we can use things like map()
return Array.prototype.slice.call(arguments);
};
var array; // Given some array of Observables that you want zipped together
// Or the more classical case where given an array of data to operate on, simply map them into observables
@alanmquach
alanmquach / chaintimer.sh
Created February 16, 2015 23:27
Breakdown the times of a redirect chain by redirect
NEXTURL="http://bit.ly"
while [ -n "$NEXTURL" ]; do
RESP=$(curl -o /dev/null -s -w "%{time_total},%{redirect_url}" $NEXTURL);
THISTIME=`echo -n "${RESP}" | cut -f 1 -d ","`;
echo -ne "${THISTIME} : ${NEXTURL} \n";
NEXTURL=`echo -n "${RESP}" | cut -f 2 -d ","`;
done
@alanmquach
alanmquach / uniq.js
Last active August 29, 2015 14:19
Find/count unique lines (i.e. 'cat filewithduplicates.log | sort | uniq -c | sort -rn')
#!/usr/bin/env node
// $ cat filewithduplicates.log | uniq.js | sort -rn | cut -f 2-
var uniq = {};
require('readline').createInterface({
input: process.stdin,
terminal: false
}).on('line', function(line){
uniq[line] = ++uniq[line] || 1;
}).on('close', function () {
@alanmquach
alanmquach / squash.js
Created May 13, 2015 22:10
Async composition
// Pyramid of doom
function go(input) {
// step 1
doSomethingAsync(input, function (result) {
// step 2
doSomethingElse(result, function (result2) {
// step 3
doYetAnotherThing(result2, function (result3) {
moveOnWithLife(result3);
});
@alanmquach
alanmquach / .bootstrap_git
Last active February 7, 2016 20:03
Bootstrap Mac shell with my bash prompt and git tab completion
echo "Downloading tab completion to ~/.tab_completion_git"
curl -s "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" > ~/.tab_completion_git
echo "Downloading bash prompt to ~/.bash_prompt"
curl -s "https://gist.githubusercontent.com/alanmquach/31d9088cf7f4126c59d1/raw/5ce769a35513a98997e5dda32b259e9ac3ece0a1/.bash_prompt" > ~/.bash_prompt
echo "Adding .tab_completion_git, .bash_prompt to .bash_profile"
echo 'for file in ~/.{tab_completion_git,bash_prompt}; do [ -r "$file" ] && [ -f "$file" ] && source "$file"; done' >> ~/.bash_profile
echo 'export BASH_PROFILE_SOURCED=true' >> ~/.bash_profile
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
source ~/.bashrc
nvm install stable
npm install rx request
@alanmquach
alanmquach / plexpip.js
Last active April 25, 2018 20:35
JavaScript snippet to hid overlay from the Plex mini-player so that the native right-click menu for the video element can be accessed (to enable PIP on Mac OS)
document.querySelector("button[title='Expand Player']").style.display = "none"