View nosense.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tput civis | |
while true; do | |
style=`cowsay -l | grep -v /usr/local | perl -p -e 's/ /\n/g' | egrep -v '(telebears|head-in|sodomized)' | gsort -R | head -1` | |
cookie=`mktemp` | |
fortune > $cookie | |
for x in `seq 5`; do | |
clear | |
cat $cookie | cowsay -f $style | lolcat; |
View letme-get-help-for-that.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
letme-get-help-for-that() { | |
cmd=$@ | |
IFS=: | |
for x in `echo "$ ${cmd} --help" | perl -p -e 's/(.)/$1:/g'`; do printf "%s" "$x"; sleep 0.5; done | |
for ((y=0;y<6;y++)); do sleep 0.5; echo -n "\b"; done ; | |
tput smul; tput bold; | |
for x in `echo "--help" | perl -p -e 's/(.)/$1:/g'`; do sleep 0.5; printf "%s" "$x"; done; | |
tput rmul; tput sgr0; | |
echo "" | |
$cmd --help |
View gist:9602702
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Given two nodes and the root of a tree find their lowest | |
* common ancestor. | |
*/ | |
public Node findLowestCommonAncestor(Node root, Node a, Node b) { | |
// If either a or b are the root, then the root is the lowest common ancestor. | |
if (a == root || b == root) { | |
// Not sure if this is a correct answer. It depends on | |
// whether you allow a node to be ancestor of itself or | |
// not. If the former the answer is correct, else null |
View gist:9592704
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Removes the list's nth from last element. | |
*/ | |
public void removeNthFromLast(List list, int n) { | |
Node ahead = list.head; | |
for (int x = 0; x < n; x++) { | |
if (ahead.next == null) { | |
return null; | |
} | |
ahead = ahead.next; |
View gist:9592308
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns {@code true} if the node is the root of a vaild binary | |
* search tree. | |
*/ | |
public static boolean isBinarySearchTree(Node<T extends Comparable> node) { | |
if (node == null) { | |
return true; | |
} | |
if (node.left == null && node.right == null) { |