infectmac.com
mystery function

What does this mystery function do?

int mystery(int input)
{
    long long n = (long long)input * (long long)0x55555556;
    long long top = n >> 32;
    int edx = (int)top;
    edx *= 3;
    int answer = input - edx;
    return answer;
}

int mystery_one_liner(int input)
{
  return (input-(((int)(((long long)input * (long long)0x55555556)>>32)) * 3));
}

What it does is simple. How it does it is not. Or at least it's not obvious at first. I still need to figure out the "magic" behind it. I think this site might be a good start: http://wall.riscom.net/books/proc/ppc/cwg/code2.html.

Anyway, in my Theoretical Computer Science class we were tasked with writing a DFA which determined if a number was evenly divisible by 3. I knew that %2 you could simply look at the last bit. But what about %3? I wrote the code for "argc % 3" and looked at how gcc with the "-O3" flag compiled it down. It's just magic. Multiply by 0x55555556? I'll figure out the "why" later.

For some reason more than two years after taking that class I decided to start figuring out the "why" to this particular compiler optimization I first ran into back then.

Note: What I have written above only works for positive integers.

reject her him twilio application

Yesterday I made http://rejectherhim.appspot.com/. It allows you to enter in your phone number and a custom rejection message. The service will also give you a phone number you can then proxy a call through. The best part about it is that with a little social engineering you can make the other person think they are getting your phone number. When you call our proxy number, and enter in the rejectee's 10 digit phone number it will connect the two of you but they will see the caller-id of our service. When they call our number back (because they think it is you) they will be played the custom rejection message.

thank you google

Google App Engine is now one step closer to making my dreams become a reality. Now if I can just get my ticket to the moon I'll be set.