Compare Files Line-by-Line (or Image-to-Image)

Two of my favorite tools for line-by-line text comparison are diff and FileMerge. One reason why I like them so much is because they are lightweight alternatives for word processors like Microsoft Word, which you wouldn’t be inclined to open for coding (that’s one of my primary uses).

diff is a simple CLI-based tool accessible on most *nix systems. The basic format is diff <options> <file1> <file2>. It comes with a lot of powerful options too. To list a few:

  • Ignore tab expansion, blank lines, and other white space
  • Ignore case
  • Ignore matching lines
  • Side-by-side output
  • Compare files in directories
  • Recurse through subdirectories
  • Reporting identical files or simply whether or not differences exist

FileMerge is as simple as it gets for file comparison with a GUI. FileMerge comes with any installation of Xcode so it’s basically free. However, you’ll have to download the whole Xcode package (~1 GB) to get it unless you can find it floating around on the net alone.

FileMerge Screenshot

FileMerge allows you to select the changes you want to keep through a menu at the bottom-right that designates the favored document. By default, the right (as opposed to left) document is selected. Below the two separate documents is the final output that will result from the merge. FileMerge also allows you to edit/add content in this section before merging and saving.

As I was writing this post, I got a referral from Russ to a cross-platform comparison tool called Perforce. The cool thing about Perforce (besides being platform agnostic) is it compares not only files and folders, but images too. Not to mention it’s FREE. I only briefly read about it and watched some sample videos on the site, but it’s pretty powerful. It also can be used in parallel with Git. Read about it here.

After the recommendation to checkout Perforce, I started doing some more research and stumbled upon a couple other tools. First off, free code editor TextWrangler (Mac) includes file comparison. Diffmerge seems like a really cool alternative. It’s also free, available on multiple pllatforms and includes merging of 3 files and integration with Windows Explorer. Kaleidoscope is another option, though you’ll have to pay ~$40. It includes many of the same features as Perforce.

What do you use when you need to compare files? Have any recommendations?

Show/Hide Invisible Files on Mac & Other Secrets

Showing hidden files can be somewhat of a pain in Mac OS X. I’ve come up with a number of ways to make it easier for myself.

The simplest, most direct way of doing this is a command in the Terminal. One way is to navigate to the appropriate directory in Terminal and type ls -lha. Alternatively, you can type ls -lha <path/to/directory>. This will give you a list of all the hidden files for that directory. But maybe you aren’t proficient with Terminal commands and/or you need to do some file manipulation and/or you don’t want to use the CLI.

Much like my post Hide Desktop Icons on Mac, I’ve created a little script I call hidden that automatically shows and hides hidden files.

#!/bin/bash

# checks file visibility and stores value in a variable
isVisible="$(defaults read com.apple.finder AppleShowAllFiles)"

# toggle file visibility based on variable
if [ "$isVisible" = 1 ]; then
	defaults write com.apple.Finder AppleShowAllFiles -bool false
else
	defaults write com.apple.Finder AppleShowAllFiles -bool true
fi

# force changes by restarting Finder
killall Finder

Paste that code into a text editor, save it to a directory in your $PATH and make it executable (chmod 755 <filename>).

HideSwitch ScreenshotTwo other alternatives I’ve stumbled upon are HideSwitch and Secrets Prefpane (at the time of this post the site was down. Get it at MacUpdate instead.) HideSwitch is just a simple mini-app with two buttons to hide and show hidden files. Secrets Prefpane is a just that: a button that shows up as a system preference and turns into a prefpane once clicked. However Secrets is quite powerful and can do a lot more than just show and hide files. Secrets includes a variety of features, such as:

  • Selecting the format and destination folder of saved screenshots
  • Changing the login window desktop picture
  • Changing Dock effects
  • Seeing the contents of folders when QuickLooking (I don’t think this works on Lion)
  • Enabling the debug menu in iCal

Those are just a few that I’ve found useful and interesting. Since it’s free, you may want to download it and check it out. Might have a feature you’ve been dying to have. Secrets also taps into many of the preferences of your other programs such as Adium, iTunes, Cyberduck, Skype, Preview, Transmission, etc.

Secrets Prefpane Screenshot

App of the Day: Sublime Text 2

Sublime Text 2 IconThere are a lot of different text/code editors out there. Some people swear by Coda ($99) or TextMate (~$50). Others prefer TextWrangler because it’s free and still has plenty of power to get the job done. If your a PC person, Notepad++ may be your weapon of choice. This post isn’t meant to be a review or comparison of the different text editors out there, but simply an introduction to another awesome alternative that I think is more unheard of than not.

Last summer a close friend referred me to Sublime Text 2. Before Sublime, I used TextWrangler, and I gotta say, the wrangler is great, but I just didn’t connect with it for some reason. I’ll admit, I didn’t really research all its functionality or install very many plugins, but I’ve heard great things. Regardless, Sublime resonated with me instantly.

Sublime is clean; no buttons all over the place. It’s got this awesome “1000 ft” distance view that can be used to scroll fast through code or find a section of your code through pattern recognition in the line structure. I’ve found it very helpful since I often use it to look through error stack traces, which are very pattern prone and are often thousands of lines long. Sublime has syntax highlighting for just about every language possible (much like other editors). You can control the preferences really easily too, changing just about any functionality. For example if you don’t like the “1000 ft view,” you can turn that off. Did I mention autocomplete? Yup…and while this isn’t language specific, it’s surprisingly smart and very helpful. Not nearly as powerful as autocomplete in Xcode, NetBeans or the like, but still a very useful feature.

These are just a few of the features that came to mind first and that I’ve found very helpful. Here’s a list of a few more (This comes straight from the documentation):

Usage

Customization

Miscellaneous

API

Oh and…Sublime is pretty platform agnostic. It’s available on Mac OS X, Linux and Windows (32- & 64-bit). You can also download “portable” versions for Windows that are self-contained so if you just want to try it out or keep it lite, you don’t have to worry about it installing extra garbage in your registry or system folders.

Sublime isn’t technically “free.” Here’s what the author has to say about that:

Sublime Text 2 may be downloaded and evaluated for free, however a license must be purchased for continued use. There is currently no enforced time limit for the evaluation.

So in other words, you can use it indefinitely without any limitations. I think it asks you to buy a license after every 25 saves or something? I didn’t find it very annoying personally. After I realized I really liked it, I just asked my company to buy me a license for work. The downside is that if you can’t work a deal like that then it costs $59 for one license.

Try it out and tell me what you think. What’s it missing? Would you switch?

*UPDATE* You should really check out Tuts+ for a list of very useful tips and tricks for Sublime Text 2. It will blow your mind if you don’t know about these features already.

Sublime Syntax Spell Checking

Syntax Spell Checking

Sublime Syntax Highlighting Javascript in HTML in PHP

Syntax Highlighting Javascript in HTML in PHP? No problem...

Sublime Multiple Selections

Make Multiple Selections

Sublime Find and Replace with Regex

Find and Replace with Regex

Sublime Edit Side-by-Side

Editing side-by-side


Mini-App of the Day: BetterTouchTool

BetterTouchTool IconIf you don’t know what BetterTouchTool is, you should read this post. If you have a Mac, you should really read this post. If you have a PC, you should still read this post. It will be worth your time to see what you are missing out on either way. It will also answer why you’d ever want to buy a Magic Trackpad if you are a Mac user and you’re saying to yourself, “Isn’t a mouse better in all regards?” For those of you who know what BetterTouchTool is and currently use it…just glory in your preeminence. ;)

BetterTouchTool is a big reason why I have loved my switch to a Mac for the last 2 years. I’ve always been a PC user. I have nothing against PC’s in general. I had some bad luck with a Dell laptop once, but I’ve seen plenty of Macs crash and burn too (some of you are probably sitting there saying, “You should have bought an HP” or “…a Lenovo.”). Though, those Asus Ultrabooks are looking pretty slick if you want the PC version of a MacBook Air.

BetterTouchTool is a utility designed to give you more control of gestures on your trackpad.  Apple did us a huge favor by making trackpads a lot bigger and by integrating the button into the pad. Genious. Apple also did us a great favor by eliminating (and returning to their old standard I might add) the second button because now if you want those menus, you just tap with two fingers. Also genious. (I realize this is up for debate depending on preference and habit, but if you are going to just argue more is better, I won’t humor you. I will entertain that two buttons–one on the left, one on the right–is just as good.)

So what does this mean? Well, Apple included a few gestures in Leopard, then a few more in Snow Leopard, then a few more in Lion. Maybe they’ll finally have a sufficient amount in Mountain Lion, though I doubt it. BetterTouchTool (BTT) makes up the lack thereof. You can go ahead and turn off most of the default gestures Apple gives you and re-program them how you want. That’s what I did. BTT allows you to add almost as many gestures as you can think of and assign them any number of preconfigured actions or a shortcut key. So now, instead of having to move your cursor everywhere or even reach to your keyboard for a shortcut, you can just use your trackpad.

For example, if you want to open and close tabs in your Internet browser, or go back and forward in your navigation history, you can do that with a gesture. You don’t need to click the button with your cursor or press Ctrl/Cmd + T or Ctrl/Cmd + [. Just program those shortcuts into gestures. This goes for any program.

Since it’s kind of hard to demo this with screenshots because you would need to verify I’m not using the keyboard, I went ahead and made a simple screencast video.

The following video gives you a short idea of how to actually “program” these gestures.

One limitation to gestures is that you inevitably run out of easy to remember and easily executed gestures. There are a lot of different gestures available, but some of them are hard to execute so chances are you will just resort back to keyboard shortcuts or cursor clicking. That said, I would encourage you to not give up after the first couple attempts to use some of the gestures. Putting all five fingers on the track pad and clicking is a little awkward the first time (just like the first time you played Halo and had to get used to the strange joystick combination or the first time you drove stick shift or rode a bike). Naturally, your muscles will adapt and you will react on muscle memory as soon as your mind thinks “Finder” or “New Tab.”

For your convenience and demo-ing. I’ve included a download of my current BetterTouchTool configuration below. I admit there is a lot of room for expansion into other apps I don’t use regularly; however, the basic and most powerful functionality that I need is there and I use it everyday. I highly encourage you to check this out and spend some time customizing it to your needs. It will highly improve your Mac experience.

Download BetterTouchTool.
Download BTT Functionality Demo Video or view on YouTube.
Download BTT Preferences Demo Video or view on YouTube.
Download My BTT Configuration File (you’ll want to remove the .txt extension before importing).

App of the Day: Console

ConsoleI currently work as a Quality Engineer at Palantir Technologies. I do a lot of feature and product testing. As a result, one of the most common tools for testing is the POSIX tool tail.

Linux/Unix/Mac users may be familiar with tail. In layman terms, tail allows you to grab a number of lines at the end of a text based file. In testing, we use tail -f <filename> a lot because the “f” option immediately and automatically updates the CLI with the most recently written lines of text in the file you are tailing. Testers love this because they like to see the stack traces printed on their screen the moment something errors in a program or system. Many development environments have consoles built in for errors and system printing and logging (think Eclipse, NetBeans, etc.). Java based programs also have the option of having the Java console automatically open when you run a Java based program.

On my Windows box at work, I use Cygwin to run the tail command. Cygwin is a Linux-like environment for Windows that allows users to port software running on POSIX systems (such as Linux, BSD, and Unix systems) to Windows. On my Mac, I just use Terminal. However, more recently I’ve discovered an even greater tool called Console. Console actually comes as a pre-installed utility with the Mac OS X operating system. I’ve found that the Utilities folder is full of great (whadoyaknow!) utility apps. I suggest you take a gander through that folder if you haven’t already. I’ve used the Grapher app in my ECON 110 class this semester a couple times (back when I used to take notes on my computer; I’ve since switched to paper since we do more graphing than anything else. Which reminds me about a great note taking app for iPad called Notes Plus. Alas, I digress. I will save that discussion for another post.).

The reason I love Console most, is because you can tell it to bounce in the dock when stack traces print to it. You don’t have to have it open on a second monitor so it’s always visible, or worse yet peaking out on the side of the screen behind the program you are testing. Better yet, you can actually choose to have it come to the forefront for a limited amount of time (say 5 seconds) and then disappear in the background again. I’ve searched for something like this on Windows and haven’t seen anything like it. Probably because there are IDE’s and stuff, but regardless, it’s a beaut. It has other great functions for console type stuff too. Check it out if you’re a tester or programmer. It might be pretty handy.

Console for Mac OS X

 

Mini-App of the Day: Caffeine

Do you hate it when your screen dims or the screensaver comes on continually? But at the same time you don’t want to get rid of the functionality to save battery power when necessary? Perhaps you are viewing something on your computer as a reference, but you don’t use the keyboard or move the mouse much?

Personally I notice screen dimming the most when I’m not plugged into a power source and I’m working with someone on a project or trying to explain something to another person and the screen keeps dimming or the screensaver comes on because I’m not moving the mouse or typing on the keyboard.

Caffeine is the best solution I’ve found for this problem. It sits in the menubar as a little coffee cup. When you don’t want the screen to dim, you simply click it. When you want to turn automatic screen dimming or your screensaver back on, click it again. You can even set it with a timeout. So say you only want it to leave the screen on for an hour or even 5 hours before returning to automatic dimming–you can tell it to do that too.

Check it out. I promise you won’t regret it. Caffeine.

Oh yeah…and it’s FREE.

Mini-App of the Day: Memory Scope

Apps that make life easier or more efficient are great. Especially really minimalist, lightweight apps that don’t eat up memory or CPU. Frequently, these are apps are menus or buttons that run in the menubar/toolbar. My favorire are the ones that are so simple you really don’t have to open them at all. They just run at login/boot and then they do their job or you click them when you need something. (A great example of this is the Dropbox app). Thus, I’ve decided to devote a fair share of posts to these amazing, small apps.

Memory Scope Logo

Today’s Mini-App of the Day is Memory Scope. I first stumbled upon this gem via Lifehacker, where I stumble upon most of my tech stuff. Memory Scope runs in the menu bar and displays how much RAM is available. If you want to free memory, you open it and a window appears showing you a histogram of total, used and free memory. It also displays the percentage of memory each app is using (similar to Activity Monitor in OS X–See the screenshot below). You also have the option of allowing Memory Scope to free memory automatically. I’ve found this to be quite helpful, esp. when I’m testing memory leaky code or opening memory intensive VM’s or when I just need to run a lot of apps at once. One of the greatest things about Memory Scope too is that it’s FREE!

You can download Memory Scope via the App Store if you are running OS X Lion.