I have my iTunes library sync’ed among my three computers using rsync.

– PC with my initial music collection (Win7)
– Synology DiskStation DS210 (tiny Linux-based server)
– Macbook (Mac OSX)

On windows, I installed cwrsync. Then I modified the provided .cmd batch file to push to the DiskStation:

rsync -avz --progress --no-g --chmod=ugo=rwX --delete --exclude='.*' --exclude '@eaDir' "/cygdrive/c/Users/Adam Klein/Music/iTunes/iTunes Music/" root@DiskStation:/volume1/Shared/music/Adam

On OSX, I pull the music:

# rsyncs remote music library to local copy

cd ~/Music/iTunes/iTunes Music/Music
rsync --iconv=UTF8-MAC,UTF8 -Xavzh --progress --delete --exclude '@eaDir' root@DiskStation:/volume1/Shared/music/Adam/ .

Initially this behaved strangely – unicode characters with accents messed up the sync. It took some googling, but I finally stumbled on the answer. Mac does something weird with UTF8. You need an “iconv” parameter in there (note it in the command above).

You can do this without having to manually enter passwords, if you get your .ssh keys set up correctly.  You create a public/private keypair using ssh-keygen, keeping the private key in your local ~/.ssh/, and appending the public key to the remote ~/.ssh/authorized_keys file.  A post on how to do it is here.

I’ll just add you can probably rsync as a regular, non-root user. But you just have to make sure all the permissions & ownership update correctly.  Things can get a bit screwy between Win7, Linux, and OSX.

I’m moving over to an iMac soon. I wonder whether I’ll give up all this manual syncing for iCloud?

Let’s talk about how (most) computers represent negative numbers. You know, the ones to the left of zero on the number line? The representation most computers use is called two’s complement.

Take the integer quantity fourteen, and think about how we represent it as a string of digits. In decimal, it’s 14. In binary, it’s 1110. Why? Remember that just as in base ten, where

14 = 1 * 10^1 + 4 * 10^0

We have, using a base of two,

14 = 1 * 2^3 + 1 * 2^2 + 1 * 2^1 + 0 * 2^0

But what is a good way to represent negative fourteen?

Wouldn’t it be great if a computer just understood -1110? The catch is, we can use only ones and zeros; using the minus sign “-” is out of the question.

We know that to represent all the non-negative integers up to fifteen, we need a string of four bits, which gives us a distinct string for each of the sixteen (2^4) distinct integers. If we want to represent the corresponding negative integers as well, we’ll have to use another bit. That doubles the number of distinct binary strings we have available, from sixteen to thirty-two.

Whatever representation we come up with for negative integers, it’s probably best if we don’t screw up normal binary arithmetic. We need to leave all integers from 0 to 15 mapped to 00000 to 01111 in binary just as they are. Remember in base ten arithmetic we “carry” if a column sums to over nine (e.g., 07 + 03 = 10). Similarly, in base two, we carry any column summing to over one.  So 00001 + 00001 = 00010; 00010 + 00001 = 00011; 00011 + 00001 = 00100; etc. This locks down all the numbers up to 01111.

What’s left to do is to assign binary representations to negative integers. The remaining binary strings at our disposal are the five digit strings ranging from 10000 to 11111. Note that all of them have one as their highest order bit. So adding two binary integers whose sum is greater than 01111 will definitely overflow into negative territory!

Now, how to do this mapping?

For a well-behaved system of (five-digit) binary addition with negative numbers, we turn to modular arithmetic, aka “clock arithmetic.” For our five-bit example in which we have a set of thirty-two binary strings, the appropriate modulus to choose is thirty-two (i.e., 2^5 or 100000). This is the midnight of our hypothetical clock on which we do our math. For example, we have that 11111 + 1 = 100000 ≡ 0. We say that 100000 is equivalent to 0. In this system of addition, which has the algebraic properties of a group (really, a ring – more on that later), every element has an inverse. This inverse (aka complement) under addition is, by definition, the negative. So with this system, we can pose the question: what is X such that 01110 + X is equivalent to 0? The answer can be nothing but the negative of 01110!

We can solve 01110 + X = 100000 (≡ 0) using only the binary arithmetic we already know. We see that:

100000 (≡ 0) = 11111 + 1 = 01110 + 10001 + 1 = 01110 + 10010

And also

100000 (≡ 0) = 11111 + 1 = 10010 + 01101 + 1 = 10010 + 01110

So it makes sense to say 10010 is the negative of 01110, and vice versa. That is, 10010 represents -14! Note, however, that this is true only in binary arithmetic with modulus thirty-two. With a word size larger or smaller than five bits, we’d wind up with different negative string representations.

The equations above demonstrate the well-known rule to form the representation of a negative binary integer in two’s complement: flip the bits and add one. This operation is known as “taking the two’s complement.”

Defining negative numbers this way allows us to define subtraction in terms of addition, so we can reuse our adder hardware circuitry for subtraction. (And lest you ask about multiplication, we’re all good there too, as our chosen system is a homomorphic image of the ring of integers!)

Note that the largest (in absolute terms) negative number we can represent using our five bits is -16, whereas the largest positive number is 15. This is because while every number from 0 to 15 has a corresponding negative, zero is its own negative. So there’s an extra negative number floating around which, strangely enough, is also its own negative.

Why is this system called Two’s Complement? Because adding a positive binary integer and its complement (negative) gives 2^w (w being the number of bits needed). You can think analogously of complementary angles in Euclidean geometry, whose measures sum up to ninety degrees. Note that for most computers today, is 32 or 64, corresponding to the native word size of the machine; it used to be 16 or maybe even 8, if you were coding for an Intel 8008 chip or something.

If you need to expand the width of a number whose word size is w to size w + k, you can do something called sign extension. This means left-padding the binary string with k copies of the sign bit. This is intuitive for positive numbers: 01110 = 001110 = 0001110, etc. For negative numbers, we can see this as follows. Imagine a binary string of length w that encodes a negative number and call it X. We know its two’s complement is X’ + 1, where X’ is just the string X with its bits flipped. As X + X’ = 2^w – 1 = 11..1 for all lengths w, whenever the two’s complement of X is left-padded with a zero (its sign bit), X must be left-padded with a one (its sign bit).

Another signed binary arithmetic system called Ones’ Complement is so named because in this system, a number and its complement together sum to 1…11; that is, one repeated w times. The rule to this latter system goes: flip the bits (don’t add one!) Unfortunately, this system suffers not least from having two distinct representations of the identity element, zero. I can only imagine the nightmare that is multiplication.

Just for fun, what might would a Ten’s Complement system look like? Suppose we have decimal strings of length two to work with, and we aren’t allowed to use a minus sign. By analogous logic, we could form negative k using the formula 10^2 – k. In which case, we’d represent negative fourteen as 86!

I went to Montreal over the weekend. I brought my iPad, natch.

But when I tried to watch Netflix or listen to Pandora, the apps told me I couldn’t access them from the country I was in.

Observation: Internet ≠ Internet Services

© 2014 Adam Klein's Blog Suffusion theme by Sayontan Sinha, modified by Adam :)