Matt Hackmann

MattHackmann

The thoughts and goings-on of some programmer dad.

A tiny PHP/Twitter script just for you!

Was rather bored this afternoon and then I though to myself "Why not add Twitter functionality to my music page?" So, after some digging through Twitter APIs and some refreshers on HTTP Authentication, I wrote this tiny, beautiful little script.


// Return values
define ("TWITTER_OK", true);
define ("TWITTER_UNAUTHORIZED", -1);
define ("TWITTER_TOO_LONG", -2);
define ("TWITTER_COULD_NOT_CONNECT", -3);

function sendTweet ($status, $userName, $userPass)
{

    // Open a socket to Twitter
    if (!($socket = fsockopen ("twitter.com", 80)))
        return TWITTER_COULD_NOT_CONNECT;
    
    // Create the headers
    $headers = "POST /statuses/update.xml HTTP/1.1\r\n";
    $headers .= "Host: twitter.com\r\n";
    $headers .= "Authorization: Basic ".base64_encode ($userName.":".$userPass)."\r\n";
    $headers .= "Content-length: ".strlen ("status=$status")."\r\n\r\n";
    $headers .= "status=$status\r\n";
    
    // Send the headers
    fwrite ($socket, $headers);
    
    // Get the response
    $response = "";
    while (!feof ($socket))
        $response .= fgets ($socket, 1024);
    
    // Check for HTTP status OK (200)
    if (!strpos ($response, "200"))
        return TWITTER_UNAUTHORIZED;

    return TWITTER_OK;
        
}

It is as simple as it looks. Enjoy!

A coding compo!

I was sitting in lab last night bored out of my skull. Yes, I could have (and should have) been working on my project, but when you're already ahead of schedule it's okay to slack off now and again.

So, as I was saying, I was sitting there and I think "Hey. I'll make a game between now and when final roll is called." I turned to Ryan and asked him what game I should make to which he replied "Space Invaders." I figured "Why the hell not? I did that back when I was fourteen." I told my bro (whom I was Skyping at the time) and he was like "Yeah, well, I bet I can make Asteroids before you can finish Space Invaders." The gauntlet had been thrown and much coding ensued.

After a couple hours of some intense typing and trying to pull down sprites off of the crappy ass wireless in the school, my Space Invaders clone was complete. Not two or three minutes later my bro finished his game, but alas it's not Flash and can't be embedded in browsers like so:

It is by no means a mind blowing or even polished game, but for just two hours I'm not complaining. And I also had a hell of a lot of fun coding it which is the important part.

I won't be a total dick and not give Chris any credit. In his defense he did create a vector renderer from scratch (I say create because technically he wasn't actually coding). His game's visuals are also far superior to mine, so be a dear and check it out as well (some Windows and DirectX are required).

I Feel Compelled to Write

It is another month and with that another wave of classes. Lucky me has class six days a week! (except next week where I only have class four days. Whatever.) So, you're probably asking "Hey, Matt! What kind of awesome stuff do you get to do this month?" To which I answer "Have you not been paying attention, compadre? Classes aren't fun anymore." This month is the exciting world of portfolio creation and business communication (see this, here, now? I'm communicating. Perhaps to businesses).

But, school aside, I've been having a rather fun time rewriting the interface to that media player I brought up some months back. This time, however, the entire front end is all ajaxy and delicious. Don't believe me? Check it out for yourself, but don't be ripping off my songs, hear? Though, you'd have to get a flash decompiler or something to actually find where they are on my server. It's all very exciting.

In some days (by which I mean tomorrow) I will the happy owner of a brand new Wii Fit (only cost me twenty extra over retail). Since I left Wal-Mart I've put on some weight - about thirty pounds. Feeling more like a pregnant lady in her third month than the macho man I am, I felt it was time to do something about that. So, I might do a weekly update thingy here as that progresses, though we all know what happens when I promise regular updates of some sort.

Every once in a while I like to google myself and my friends, probably because I have far too much time on my hands. It's an interesting thing to do and one I recommend to my peers (by which I mean other internet micro-celebrities). Interestingly, I seem to have the most web presence of the classmates I googled. Granted, I have had a little bit of a head start and a bump here and there. I suppose it isn't the most common thing ever to be featured on the front page of various gaming sites (twice), but surly somebody in that class has done something that's caught the attention of the internet. Then again, I do seem to be that guy as devusb so fervently calls it, and unfortunately I have to agree. That's probably why I still spend most of my time alone with my computer while everybody else is out smoking weed and getting laid. Or perhaps the internet fame happens because I stay at home by myself. But, we're not here to get into the chicken/egg debate. Actually why don't we.

Q: Chicken or the egg. Which came first? A: Who cares, they're both delicious.

Well, I suppose that's enough nonsense for one afternoon. Besides, I have other equally unimportant things I could be doing, like checking digg/Joystiq/Engadget, stalking people on Facebook/Twitter, binge drinking all my troubles away, the usual.

Perhaps some dusting is required

It's been quite some time since I last graced the interwebs with my esoteric writings. Much has happened since then and, on the flip side, much hasn't happened since then. Hell I don't even remember what the last thing I wrote was. But, no matter. That's why God invented tabbed browsing.

Going back over some of my more recent posts, it seems that I made some sort of attempt to be more... professional. That is, I attempted to be a help to the community at large, injecting into it my insights and examples. However, after some recent soul searching over break, I realize that this is not who I am, nor is it who I wish to be. I simply wish to be myself and for my blog to continue on much the way it has for so many years. That is to say, contain the trials, tribulations, and joys of my life. So, with so much time to catch up on, where does one begin? I suppose it's best to find out where one left off...

I suppose the last meaningful post was about the anime festival I attended in August. Now, back then I felt like an outcast amidst a lot of freaks (in a good way, however). But, since then, I too have fallen victim to the Japanese and tantalizing animations. I suppose the beginning of my downfall was when I picked up and was subsequently sucked into the Phoenix Wright games. It didn't help that I was prodded along the way by a buddy of mine (who will be called Ryan for lack of a made up name). He showed to me Hellsing, an anime about some vampire killing organization, the Catholic Church, and nazis. As crazy awesome as this combination may sound, vampires and the occult really aren't my forte. So, he pushed me towards Dragon Ball Z, which, I must admit, is not only awesome, but totally over nine thousand. From there I ventured out on my own checking out anime on Netflix's instant watch (Project A-ko and Best Student Council). My biggest pitfall was when Hulu picked up Naruto. Everybody and their chibis seemed to be completely enamoured with this show and, even though I'd previously shunned it as I had all anime, I watched an episode. And another. Two weeks later and not only had I watch one hundred twenty episodes, but I'd also read all the manga after the point I'd left off. I've also watched and completed Lucky Star (all the dubbed versions, at least) and the Meloncholoy of Haruhi Suzumiya. So, I can no longer consider myself the portent of anime's destruction (as I once wanted to be). Instead, I am a lowly otaku. Damn.

School-wise, nothing terribly interesting has happened. I've completed all my film courses, made a level for UT3, created a magazine and TV packaging, and now I'm back to web design. How I hate you, web design. Web programming, that's okay. I enjoy programming, However, I'm beginning to realize how much I don't enjoy actual design. The process of coming up with some idea out of nothing is one I find very difficult (though, I usually execute it fairly well). However, with programming I know what I'm trying to achieve and the steps to get there a fairly linear and even allow for a good bit of problem solving which I do love. That said, I still enjoy film making and motion graphics.

The good news about school is that I've got less than half a year left until graduation. I'm not entirely certain what I'll do after that. One thing I do know is that I'll be heading back home for a couple months to simply do nothing. Full Sail, while it hasn't been terribly difficult has left me drained of nearly every creative juice in my body as well as killed off almost all of my motivation. That can be attributed to the fast pace of the scheduling where every month I have to design my way out of another two classes. I've enjoyed my time here, but I'll also be glad when it ends. It means I get to go on and do something awesome (hopefully VFX, programming, or motion graphics).

Other than that nothing very exciting has happened to me. It's all school and what play there is generally involves me sitting on my ass in front of this computer monitor surfing the nets or whatever recent project has caught my fancy. I promise that I won't let another agonizing two months go by before I update again, but with nothing happening it's hard to find something to write about. Perhaps you should follow me on Twitter for all the little random things and thoughts of mine. Until next time, be cool and stay in school.

Display Time Code in After Effects with Expressions

Whilst working on my current video project, I came across a need to display the current time code. Expressions are the answer, of course, so I came up with this.

txt = "";
frames = timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false);
f = frames % 30;
s = Math.floor(frames / 30);
m = Math.floor(s / 60) % 60; s %= 60;
h = Math.floor(m / 60);
if (f < 10) f = "0" + f;
if (s < 10) s = "0" + s;
if (m < 10) m = "0" + m;
if (h < 10) h = "0" + h;
txt = h + ":" + m + ":" + s + ";" + f;
txt

Simply attach this expression to the Source Text property of a text layer and viola!