Textwrangler Tips – Compare files, keyboard shortcuts

A few quick TextWrangler tips.

I never knew until recently that you can compare files in TextWrangler… and its easy.

Simply highlight the 2 files you want to compare in the Documents drawer, right click on them and select the option ‘Compare Selected Documents‘.

Now the 2 files will open into 2 windows with a review of the differences below them. You can then apply the differences in either direction.

Another tip is adding keyboard shortcuts to TextWrangler’s menu options.
Continue reading “Textwrangler Tips – Compare files, keyboard shortcuts”

Odd or Even Number

I love gems like this. I come across them from time to time but they never stick… then I do a search to find them again.

Anyway a simple way to determine if a number is odd or even, use the following code.

function is_odd( $number ) {
    return $number & 1;
}

Quick explanation
& is a binary AND.

If you have a binary value, and you AND with another binary value, then the result will be the bitwise AND of the two.

Binary values are a series of bits or 1’s and 0’s. However we are only concerned with the rightmost one ( the least significant bit ) as when a binary value ends with a 1, it is odd… when it ends with a 0 it is even.

Now, if I pass that function say the number 13, the binary value will look like 1101.
When you AND with a 1, or binary value 0001, it looks like this…

1101 & 0001 = 0001

We look to the least significant bit, which is a 1, which means the number is odd.

A simple explanation of binary can be found here.