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

Two shortcuts for displaying system_profiler data types

man system_profiler

function sptypes() {
   /usr/sbin/system_profiler -listDataTypes | /usr/bin/sed '1d' | /usr/bin/sort | /usr/bin/nl
   return 0
}

unset -f sptype
function sptype() {
   declare -i num
   declare sptypename
   num=$1
   #sptypename="$(/usr/sbin/system_profiler -listDataTypes | /usr/bin/sed '1d'  | /usr/bin/sort | /usr/bin/nl | /usr/bin/egrep "^[[:space:]]+${num}[[:space:]]" | /usr/bin/awk '{print $NF}')"
   sptypename="$(/usr/sbin/system_profiler -listDataTypes | /usr/bin/sed '1d' | /usr/bin/sort | /usr/bin/nl | /usr/bin/grep -w "${num}" | /usr/bin/awk '{print $NF}')"
   printf "\n\e[1m%s\e[m\n\n" "${sptypename}:"
   system_profiler "${sptypename}"
   return 0
}


sptypes
sptype 5

sptypes | grep -i pref
sptype 26 | less -R


#------------------------------------------


# interactive version
unset -f sptype
function sptype() {
   declare -a array
   declare -i num
   array=($(/usr/sbin/system_profiler -listDataTypes | /usr/bin/sed '1d' | /usr/bin/tr '\n' ' '))
   echo
   printf "%s\n" "${array[@]}" | /usr/bin/nl
   echo
   printf "\n\e[1m%s\e[m" "Please select a number:  "
   read num
   num=$num-1
   echo
   printf "\n\e[1m%s\e[m\n\n" "${array[${num}]}: "
   system_profiler $(echo "${array[${num}]}")
   #system_profiler $(echo "${array[${num}]}") | less -R
   return 0
}

sptype

Fix orphaned users in MSSQL

Thanks to CodeProject for this code

Run this in the Query Analyzer (make sure the right database is selected first).

sp_change_users_login 'auto_fix', 'UserName'

Retrieve MSSQL table information

Retrieve tons of information (length, data type, name, etc.) of columns for a table. Works in (T|MS)SQL (all I've tested it in).

SELECT * FROM information_schema.columns WHERE table_name = 'Customers'