mlogo
Archives
  • Fundamentally, people do not like to learn. They like to affirm and extend what they already know. #

Powered by Twitter Tools.

Wednesday 4/30 around 11 pm   No Comments »

I rode this while in Shanghai in 2006. This captures the ride pretty well.

Wednesday 4/30 around 1 pm   No Comments »
  • Insomnia is way under-rated these days. #

Powered by Twitter Tools.

Tuesday 4/29 around 11 pm   No Comments »
  • Richard Nixon was, in all likelihood, never a pastor. #
  • Seriously, Microsoft Office 2008’s spell checker still does not recognize the word "Podcast" or even "Blog" by default? #
  • @wilharris Last.fm does, I believe. #

Powered by Twitter Tools.

Monday 4/28 around 11 pm   4 Comments »

If you have ever developed in PHP, you have likely utilized the amazing strtotime function. It lets you throw any string at the function, and it returns an integer UNIX Epoch timestamp. It’s incredibly flexible. All of the following will return a valid UNIX timestamp:

  • strtotime("Nov 2, 1984");
  • strtotime("Nov 2, 1984 5:34AM");
  • strtotime("Nov 2, 1984 15:34");
  • strtotime("Last Tuesday");
  • strtotime("Tomorrow");

Now that I’m doing some work in Cocoa, I really miss this capability. Thankfully, as every copy of OS X (at least since 10.4) has shipped with /usr/bin/php installed by default, we can call it from Cocoa! Here is some code that will return an NSDate from a string, via PHP’s strtotime();


-(NSDate *) stringToTimeViaPHP:(NSString *)aString
{
    NSTask *task;
    task = [[NSTask alloc] init];
    [task setLaunchPath: @"/usr/bin/php"];

    NSString *strToTimeArgs = [NSString stringWithFormat:@"print strtotime('%@');",aString];

    NSArray *arguments;
    arguments = [NSArray arrayWithObjects: @"-r",strToTimeArgs, nil];

    [task setArguments: arguments];

    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    NSFileHandle *file;
    file = [pipe fileHandleForReading];

    //NSLog(@"Launching %@ ",[task arguments]);
    [task launch];

    NSData *data;
    data = [file readDataToEndOfFile];

    NSString *string;
    string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

    int dateInterval = [string intValue];

    theDateTaken = [NSDate dateWithTimeIntervalSince1970:dateInterval];
    //NSLog(@"The date stands as %@",theDateTaken);

    return theDate;
}

I’ve only tested this on Leopard (Mac OS X 10.5.2), but it should work on Tiger as well. I am releasing this code under the MIT License. Let me know in the comments if you find it useful in your app.

Monday 4/28 around 5 pm   No Comments »
  • Seriously, is Comcast Baltimore ridiculously slow for anyone else this morning? #

Powered by Twitter Tools.

Saturday 4/26 around 11 pm   No Comments »
  • Jobs are such strange things… You actually have to do them! When some people don’t, Michael gets angry… #
  • Move the mouse… Now, click it! Click it you fool! #

Powered by Twitter Tools.

Friday 4/25 around 11 pm   No Comments »
  • Katie passed her orals!!! #

Powered by Twitter Tools.

Wednesday 4/23 around 11 pm   No Comments »

It turns out you can play with the URL in the new CNN Shirts site. This would be a perfect CNN Headline.

Via Ryan Block.

Monday 4/21 around 12 pm   14 Comments »
  • How many people can say they’re stuck in Papal traffic? #
  • Does anyone find it odd that Costco sells funeral supplies (coffins) in bulk? http://tinyurl.com/2lybzd #
  • Damned spammers. #

Powered by Twitter Tools.

Wednesday 4/16 around 11 pm   No Comments »
« Previous Entries