Accomplished!

I’ve spent the past 5 hours pounding my head against the desk trying to self-teach myself everything about PHP sessions, objects, and MySQL accesses all at the same time by building the login/registration portion of my webapps final project. But hey, it was all worth it, because I understand them now!

The more I do webapps stuff, the more I think this is what I want to do with my life. I can’t identify what it is about writing PHP (or, to a certain extent, JSP or Java Servlet) code that is so addicting… but once I start, I just can’t stop. I can’t tell you how many times I’ve found myself sitting at my computer until $late_hour writing webapp code… and that rarely happens with any other kind of program.

So yeah, I spent a while trying to fix mistakes that came about from misunderstandings about PHP (trying to teach yourself 3 new things at once doesn’t make it easier to learn any one of them)…
-The header() function doesn’t automatically dispatch. You must call exit afterwards if you want to immediately dispatch the headers (ex: redirect to a new page).
-Starting a session (with session_start()) automatically calls in all saved session variables, overriding any existing variables. I couldn’t figure out why the hell $username was being overridden until I realized I hadn’t lost my previous session (which contained a duplicate $username variable), and it was loading the variables.
-You cannot use session_unset() if you set variables through $_SESSION
-If a function returns either an object or false, you cannot do testing with !$variable, you must do $variable!=false (but you can do that with functions that return either true or false).
-Defining things with define() in an if statement doesn’t carry over into the global scope (although this problem might have stemmed from one of the previous misunderstandings).
-The general hash() and hash_hmac() functions are only in PHP5, and my server only has PHP4.
But hey, I got everything working… now I can start on the fun part.

I really should be asleep given that I have class tomorrow at 7:30 followed by an exam. Blah at that.

It’s a Todd! For some reason I like this picture a lot.

Interview’d

So today was my interview with Google. Overall, I feel like I wasn’t nearly up to par. I had a couple of “Oh god, DUH” moments when the interviewer said something about my algorithm(s). I should also learn to start trusting my instincts… my first instinct on one of the problems (floor of sqrt) was right-ish but I tried to over-complicate it, which was actually a worse solution (same runtime, but with much more memory usage).
I also screwed up one of the problems which *should* have been straightforward to do.
Oh well.
I really wish I interviewed better. I know the stuff, really… meh.

Pittsburgh has been kinda crazy lately. According to the papers, there’s a highway that motorists have been stuck on since Wednesday evening due to the snow and road closures and everything. The T light rail system also shut down due to freezing rain on the power cables that make it go.
On the plus side, all the freezing rain around makes for some pretty damn nice pictures.

Also on the plus side, I’ve been photographing again. I spent most of last night in the darkroom and studio making images. Whee.

Housing for next year has more or less been taken care of, so that’s one thing down at least. Now I just wish I could get a job for the summer. Meh.

OMG workdeath has started. I now have 3 major projects that I’m working on concurrently, plus a photo presentation for Monday, plus an exam in graph theory on Monday. Grrr.
*goes off to do work*

Musings

I have a bunch of angst I want to write, but I’ll spare you. If you’re really all that interested, you can ask, but I won’t promise I’ll tell.

I finished my web apps homework today in about 4 hours. We had to write an online dating service program that users could create accounts for and use to search the userbase for people matching their criterion, implementing sessions and authentication and all that good stuff. It was fairly easy, given I’ve done a lot of php before (even though this was written in Java as a servlet). So yar.

My partner (Mike) and I are done (pretty much) with our networks project 1. We had to write an SMTP client that would send email using the SMTP protocol. It was easy enough… the hardest part was implementing DNS lookup for MX records due to horrific documentation on the resolver() set of functions. Meh.

So yeah, between those two classes, my life is full of coding, and it’s making me feel happy (….somewhat).
Code is so straightforward… so precise… unlike pretty much everything else in my life right now. Which is to say that nothing in my life is going right at the moment, except for my CS courses.
Meh.

I bought a ton of legal MP3s last night from MP3 Tunes and eMusic. I paid something like $10 and was able to get 4 complete albums (thanks to the free trial downloads thing from eMusic). The best part is that the artists get the large majority of the purchase price, unlike with other methods with the large record companies. Meh. DRM is stupid as hell… buy your music from these sites instead. Whee, I’m starting to sound like Zeke.
Yay for Adam Pascal, Christopher Jak, and Groove Coverage being on independent labels who aren’t assholes with their heads up their butts trying to scam the artists and, to use Zeke’s words, biting the hands that feed them.

Um… yeah.
I don’t want to post pictures at the moment, because thinking about photography right now is making me feel shitty. It’ll probably be a while before I voluntarily pick up a camera again (not counting class assignments, obviously).

Ben is teh awesomely awesome. I have amazing friends… I’m so lucky…

Food/ITG

I made fresh garlic mashed redskin potatoes tonight. They were yummy. I put them over pasta, so they were kinda like inside-out perogies. Mmmmm.

In ITG news… passed Energizer Hard today (the 10-foot). Also came close to my first star… 95.88% on Pandemonium Medium. Set new personal records on Infection Hard (94.29%) and Utopia Hard (90.68%) as well. The other day, I also improved my score on Charlene Expert (up to a ~67.5%) and passed Driven (a marathon course). Yay for ITG funness. I’m also playing some doubles now, and I can pass 7s. Haven’t yet attempted an 8, because I’m still having trouble recognizing the patterns in the steps and locating myself on the two pads.

Today was the Fairfax BBQ, and there was lots of food and yummyness as well.

There are now pictures of me playing ITG, thanks to Ben.

So I’ve been avoiding large groups of people lately, and it’s working out well. I’m just so much happier when it’s just me and one other person, or a couple other people. I dunno… it’s kinda a complete change from where I was (used to seek out huge groups on purpose), but I kinda like it better this way. I’m never invited to events and foo anyway, and no one tells me about parties that are happening, so meh.

Got my graphics homework mostly done. I was getting hung up on the stupidest thing… apparently OpenGL processes transformation commands backwards, since it sticks them on a stack and pulls them out. I spent the longest time figuring out why my “translate to (0,0) and then rotate” wasn’t working properly. Reversed the order of all my function calls, and everything worked perfectly. Bleh.

Err… yeah

Poor Facebook, but also WTF?!?
I think Matt puts it better than I ever could. See here.
It’s true though that it’s impressive as hell that they coded something like this. I mean, I can’t imagine how difficult it must be to keep track of every single action a user makes and then broadcast that to all of said person’s friends… I imagine the algorithm to do that had to be optimized a ton to make page loads bearable. Or I guess, depending on how they have friend structures organized (I imagine as a graph with bidirectional edges), it’s really not that difficult, just space-intensive.

I got new glasses today. They make me happy, I think. I’m gonna have to get used to wearing them higher up on my nose since they’re not as tall as my old ones. Also got a bunch of gummy treats from my parents… and 16 rolls of film. Yay film!

Yearbook meeting was today. Tomorrow is the Activities Fair. Whee.

Algo algo algo algo
Quicksort, quicksort
Algo algo algo algo
Quicksort, quicksort
Algo algo algo algo
Quicksort, quicksort
Algo algo algo algo
Ahhh it’s a Tom, a Tom, ohhhh it’s a Tom

Edit: Actually, this is interesting to think about, from a technical point of view… and I guess it’s not as simple as I originally thought.
Let’s say a user has n friends. Each person has their last 10 actions stored (this isn’t exactly true, since you can delete actions and older ones take their place… and I haven’t deleted enough of mine to see how many they store). Finding the last k actions by your friends incurrs an automatic lookup of 10nlog(10n) to sort all the actions and find the k most recent. Many of these actions may also incurr an additional cost, as they require looking up the tagged people (i.e. photos or notes) in your friends list to see if they exist… likely either a cost of n or 1 amortized, depending on how friends links are stored. Either way, that’s unimportant asymptotically, so you incurr an automatic cost of O(nlogn) with every home page view, assuming the content is generated dynamically, which it seems to be.
Dealing with issues of untagging, deleted groups, removing your actions, and such seem to be relatively easy… just delete the corresponding entry in the log for the person (incurring an additional O(n) each time someone does one of these actions), and those actions are automatically removed from any feeds.
Dealing with multiple people joining a group seems to be more difficult though, since the feed combines such things into “X, Y, and Z joined group G”. This likely incurrs another computation of order n (although I guess they could process duplicates here too, like if two of your friends entered a relationship).
Some people have on the order of 1000+ friends. I don’t even want to think about how many people are logging into facebook (and seeing the home page with the feed info) at any given time.
Even an algorithm that can run in O(nlogn) would be immensely horrible to generate on every login… I can’t think of anything else on Facebook right now that has to do that, besides your friends page (ordering friends by profile update time), which people probably don’t use as much.

The feeds on each user’s page probably aren’t as bad… tagging someone probably adds an action to their log that they were tagged and such, which doesn’t seem incredibly time-intensive, and it’s trivial to store what the user did and then sort the actions.

Meh. My analysis is probably all wrong… but still, it’s quite impressive what they managed to achieve.
Too bad it wasn’t a practical application :-\