Hey OS X Lion, did you eat my Library folder?

Mac OS X Lion (10.7), introduced a bunch of new features to the Mac platform. At the same time it’s taken away some things that experienced Mac users are used to. The idea was to remove things that the average user doesn’t need.

If your like me, you might have yelled “Hey! Where is the Library folder in OS X Lion?”, when trying to access data from the iPhone simulator.

After doing some research, I found that the folder was not gone, it had simply been hidden. Running the following command from the terminal, I was able to make my Library folder visible once again.

chflags nohidden ~/Library/

You may also need to restart finder by using this command

killall Finder && open /System/Library/CoreServices/Finder.app

If for some strange reason you want to go back to being a n00b and hide the Library folder again, you can use the following command

chflags hidden ~/Library

Mac: Rename all files names in a directory to lower case

Just like my last post, I was working with a directory of about 1000 files. There were all sorts of problems with the way they were named. Anyone who is used a *nix type system will know that “.jpg”, “.Jpg”, “.JPG” are all very separate things. To solve the issue I was having I needed to rename all of the files in the directory to lowercase.

I fired up my friend the Mac terminal and ran the following command:

for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done

The code loops through each of the files in the current directory and renames it to the lowercase equivalent. fast, simple, elegant. Major time saver.

Mac: Converting a directory of images into JPG files

Recently I was presented with a problem where I had a directory of about 1000 graphic files of mixed formats (png, gif, bmp, jpg), and I needed to convert them all to jpg files.

I tried various solutions but I ended using the following command in my Mac’s terminal.

mkdir jpegs; sips -s format jpeg *.* --out jpgs

This command creates directory called “jpgs”, and converts all of the files in the current directory into .jpg format, and moves them into the newly created “jpgs” direcotry.

It truly saved the day.

Dude I’m speaking at WordCamp OC!

That’s right, I’m speaking at the 2011 Orange County WordCamp, May 14th.

What is a WordCamp? WordCamp is a conference that focuses on everything WordPress. WordCamps are informal, community-organized events that are put together by WordPress users. Everyone from casual users to core developers participate, share ideas, and get to know each other.

I’m going to be presenting the topic, “Optimizing WordPress: Speed Matters”

By itself, WordPress is fast and snappy application but over time your site may become sluggish and laggy. A slow site is not good for your readers, or your search engine rankings. In a one hour presentation, I’m going to show some practical ways to optimize your WordPress sites content and configuration. The presentation will cover best practices, helpful plugins and real life optimization examples.

I’m excited to check out the other topics that are being presented. The OC WordCamp has three distinct tracks of sessions, beginners, advanced, and business minded users.

If you’re free on May 14th 2011 and love WordPress, you should come and hang out with some fellow WordPress users. http://2011.oc.wordcamp.org

Letting the database to the heavy lifting: Capitalization via SQL

Years ago I had the pleasure of meeting Ben Forta and listen to his thoughts on web development. One thing that stuck with me was his statement that:

“Dynamic programming languages like PHP and Coldfusion are great, but developers need to leverage the database more. Allow the database to do it’s job, the heavy lifting”

With that being said, I was recently working with a database that contained users first names. The data was not snantized at entry, and contained a mix of lower cased (ex. josh) and upper cased (ex. Josh) first characters in the firstname column. I needed to always present the users first name in a capitalized format.

The first solution that most developers would reach for is dynamically parsing the users first name, then upper-casing the first character. This works, but in my opinion isn’t the most elegant solution.

With a simple SQL statement, like the one below, we can return the users first name already in a capitalized state.

SELECT (UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname))) as firstname 
FROM users
It’s quick to implement, its easy to work with, and it’s also very fast on the performance scale.
Yes, I understand that there are cool convenience functions in like ucfirst() in PHP, but I’m a lazy programmer and I don’t want to have to remember to use ucfirst() every time I’m dealing with the users name. I’d rather get the information in the correct format the first time, then remembering to groom it every time before I use it. Set it and forget it.