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

Get network service information on Mac OS X

# cf. http://www.macosxhints.com/article.php?story=20050214200529336

function network_service_name() {

   SERVICE_GUID=$(printf "open\nget State:/Network/Global/IPv4\nd.show" | \
      /usr/sbin/scutil | /usr/bin/awk '/PrimaryService/{print $3}')

   SERVICE_NAME=$(printf "open\nget Setup:/Network/Service/${SERVICE_GUID}\nd.show" | \
      /usr/sbin/scutil | /usr/bin/awk -F': ' '/UserDefinedName/{print $2}')

   echo $SERVICE_NAME

   return 0

}


network_service_name

# cf. systemsetup & networksetup, http://codesnippets.joyent.com/posts/show/1691
/usr/bin/sudo /usr/sbin/networksetup -getinfo "$(network_service_name)"


# further network management command line tools:
# - http://turin.nss.udel.edu/programming/ncutil/
# - http://turin.nss.udel.edu/programming/ncutil/UsersGuide/index.html
# - http://www.julien-jalon.org/sysprefs/index.html

Case sensitivity in PostgreSQL

When I started using PostgreSQL, it seemed odd that when I created a table called Users with column names like userId, userPassword, etc. When I would select these items from the table, the column and table names would all be in lowercase. It's quite simple really, I wasn't using quotes :) Below is an example of how to maintain your case in PostgreSQL:

This will all come out lowercase
create table Users (
  userId integer unique not null,
  userFirstName varchar(50) not null,
  userLastName varchar(50) not null
);


Whereas this will come out as you expect it to
create table "Users" (
  "userId" integer unique not null,
  "userFirstName" varchar(50) not null,
  "userLastName" varchar(50) not null
);