Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

1 total

On This Page:

  1. 1 snippet

snippet

Download code snippets (http://textsnippets.com) from the command line and convert them to text files using man textutil (on Mac OS X 10.4).

Usage:
snippet 345
snippet 1268
snippet 1281



# $ cat $HOME/.bash_login

function snippet() {
   /bin/mkdir -p ~/Desktop/Snippets
   OPWD="$PWD"
   cd ~/Desktop/Snippets
   /usr/bin/curl -L -O -s --max-time 25 http://codesnippets.joyent.com/posts/show/"$1" || exit 1
   file="${HOME}/Desktop/Snippets/$(basename $_)"
   /usr/bin/textutil -convert txt "$file"
   /bin/rm "$file"
   new_file="$file.txt"
   /usr/bin/sed -i "" -e '1,5d' -e 's/.See related posts.//' "$new_file"  # delete first 5 lines of file
   /usr/bin/sed -i "" -e :a -e '1,6!{P;N;D;};N;ba' "$new_file"            # delete last 6 lines of file
   cd "$OPWD"
   return 0
}


1 total

On This Page:

  1. 1 snippet