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!)

About this user

Rob Nugen http://robnugen.com

javascript value of selected option

// what is the value of the selected option?

this.options[this.selectedIndex].value

scp to my journal

// copy entries to journal

// simple snippet that shows taking a command line variable and doing a longer command that includes that variable

#!/bin/bash        
if [ -z "$1" ]; then 
    echo usage: $0 "MMM (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec)"
    exit
fi
MMM=$1
scp *.html robnugen.com:$MMM"_journal"

find foo in directories, but foo on .svn directories

// search for foo in all .php files in the dir tree, but skip .svn directories

find . -path .svn -prune -o -name *.php | xargs grep foo

bash shell code to replace text in multiple files, multiple dirs, (but not in SVN dirs)

find . -name          *.php -exec sed -i 's/oldtext/newtext/g' {} \;
find . -name .svn -prune -o -exec sed -i 's/oldtext/newtext/g' {} \;


My understanding:

find files starting with . (local directory)

-name .svn -prune means if you find .svn for a filename (directory name), skip it.

-o OR

-exec execute

sed -i sed is the stream editor. -i means change the files in place.

's/new/old/g' Substitute old text for new text Globally.

{} sends the filenames that find found to sed

\; terminates the -exec from find, and \ escapes it so the shell won't think it means to end its command.