Howto

Mac Terminal tip: pbcopy and pbpaste

June 4th, 2008  |  Published in Howto, Mac

Just found two helpful programs in OS X; pbcopy and pbpaste (man page). They let you write and read from the OS X clipboard and allow you do to things like:

$ cat file.txt | pbcopy
That’s a lot faster than opening the file, selecting everything, and copying it!

$ pbpaste > example.css
Quicker than firing up emacs/TextMate/whatever.

Of course you can even do fancier things like:
$ tail -n 10 /var/log/messages | pbcopy

So good!

How to create an iPhone ringtone without GarageBand

May 31st, 2008  |  Published in Howto, Mac, iPhone

There are lots of articles out there explaining how to make an iPhone ringtone from a song using GarageBand but it’s also possible to create them using only iTunes. Here’s how:

  1. Find the song you want in iTunes.
  2. Right click on it and select “Get Info” (Apple+I also works). Go to the ‘Options’ tab.
  3. Adjust the “Start Time” and “Stop Time” values to shorten the song down to the part you want to use for the ringtone (45 seconds max). Click “OK”.
  4. Play the track and make sure you’re happy with where you’ve set the start and stop times.
  5. Right click on the track again and select “Convert Selection to AAC”. This will copy the part of the song between the “Start Time” and “Stop Time” into a new file in AAC format. Once it’s done encoding, the shortened track will appear in your music library.
  6. Right click on the original track, select “Get Info” again, and reset the start and stop time values to what they were before we started (probably both unchecked).
  7. Right click on the new AAC-formatted track and select “Delete” (Apple+Backspace also works). Select the “Keep File” option when prompted.
  8. The AAC file is no longer in your iTunes library but is still on your hard drive. Find it by searching for it in Spotlight or browsing to your iTunes Music folder directly.
  9. Select the file and hit ‘Enter’ to rename it. Change the extension from .m4a to .m4r. Hit enter again.
  10. Double click on the file and it should open up in iTunes and be placed in your “Ringtones” folder on the side.
  11. Make sure you’re syncing ringtones with your phone, perform a sync, and enjoy!

Update (2008-6-14): This also works in iTunes on Windows!

TextMate tip: Validate PHP syntax when saving

May 10th, 2008  |  Published in Howto, Mac, PHP, Programming, Software

The JavaScript Tools bundle for TextMate automatically runs JavaScript Lint on your files when saving and shows a little tooltip if there are any errors (like the missing semicolon below).

It’s very easy to enable similar functionality for PHP files. The default TextMate PHP bundle already comes with a ‘Validate Syntax’ command but it’s bound to Ctrl+Shift+V. Here’s what you need to change:

  1. Open up the Bundle Editor by hitting Ctrl+Option+Apple+B or opening the Bundles menu and selecting Bundle Editor > Show Bundle Editor.
  2. Find the PHP bundle in the list on the left and open it up.
  3. Select the ‘Validate Syntax’ command and then change it’s ‘Save’ option to ‘Current File’ in the dropdown on the right.
  4. Change the keyboard shortcut to Apple+S (or whatever you use to save) in the lower right. Your settings should now look like this.
  5. Close the Bundle Editor (it saves your changes automatically).

Below is an example of what you’ll see when saving. It will even move your cursor to the line with the error!

Update (2008-5-23): You can prevent the tooltip from displaying when there are no syntax errors by changing the command to:
#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + ‘/lib/textmate’
version = %x{#{ENV['TM_PHP'] || ‘php’} -v}.split[0..2].join(’ ‘)
#puts “Running syntax check with ” + version + “…”
result = `#{ENV['TM_PHP'] || ‘php’} -d display_errors=on -l`
puts result.gsub(’in -’, ”) unless result =~ /No syntax errors/
TextMate.go_to :line => $1 if result =~ /line (\d+)/

Crysis intro videos; just let me play!

May 4th, 2008  |  Published in Gaming, Howto, Rants

One of my main reasons for upgrading my computer recently was so I could play Crysis, and for the most part I’ve really enjoyed the game. The one thing I just don’t get is why they make you sit through so many damn intro videos each time you load the game. I realize that companies need to advertise, but the time it takes to load Crysis is ridiculous and creates enough friction that I’m sometimes just too lazy to play. Here’s what you have to go through:

  • EA logo - Just in case I forgot who published this (and almost every other) game. Luckily Crytek did such a good job with Crysis that even EA couldn’t mess it up.
  • Crytek “Maximum Game” logo - Since Crytek actually made the game, it seems fair to let them use this space. They should let me skip the screen by hitting Esc, however.
  • NVIDIA logo - I’ve already given you hundreds of dollars by buying your video cards and motherboards. Now you’re just wasting my time.
  • Intel logo - Same as above, although I’m running an AMD in this machine. Maybe this tricks some people into thinking they should be using Intel for playing this game.
  • ESRB Notice: Online interactions not rated by the ESRB - Great. Isn’t putting this on the box enough? Does anyone care besides parents when they’re in the store buying the game for their kids?
  • “Crysis, by Crytek” - In case I had become so bored waiting through the previous screens that I actually forgot what game I was waiting to play. WTF?

Is it really worth it for publishers (not that EA is known for being kind) to jam so much advertising into my gaming experience? Luckily you can just rename a few files in order to bypass the videos (what a great and accessible user experience). Just go to the Crytek\Crysis\Game\Localized\Video\ directory and rename (or remove) all the .sfd files starting with ‘Trailer_’, including the one in the ‘English’ directory. Next time you start the game you’ll find yourself at the menu within seconds! Sorry NVIDIA, but this is the way it’s meant to be played.

Uploading a Picasa album to Flickr

February 25th, 2007  |  Published in Howto, Photography, Tech

Google’s Picasa is by far my favorite photo application and I’ve chosen flickr to share my photos due to its popularity and cheap pro plan. Unfortunately there’s no flickr plugin for Picasa since it doesn’t even support plugins. When I want to upload photos I have to manually drag them from Windows Explorer into the flickr uploadr. This works acceptably well for a small number of photos (hitting ctrl+enter on a photo in Picasa will reveal it in Explorer so you don’t have to track it down by filename) but for a large set, like my recent trip to Italy, it would take hours! I took about 1000 photos in Italy and had selected about 130 that I wanted to put on flickr. The fastest way I found to get this group of photos onto flickr was;

  1. Add all the photos to an album (I called mine UPLOAD)
  2. Select the album in the album list on the left
  3. Click the ‘Export’ button in the bottom right of the Picasa window
  4. Export the images to a folder on my desktop
  5. Drag this folder into the flickr uploadr (and then wait a few minutes while it adds the images…)
  6. Upload!

Since Google has Picasa Web Albums I doubt they’d make an effort to improve Picasa -> flickr integration but maybe someone will be able to hack some flickr options into Picasa at some point. I’m just glad I don’t take too many pictures or this process would drive me nuts.