RSS
 

Archive for February, 2008

Fun office pranks

08 Feb

One of our co-workers recently managed to leave his computer unlocked when he left work for the day. Time for hilarious pranks!

The standard “punishment” for leaving ones computer unlocked is to modify their system settings, often times setting their background to something humorous or embarrassing.

Katy wrote up a long blog post explaining in detail how to hijack the background of an unlocked mac, inspired by a prank we pulled on a co-worker who made just such a mistake. In summary we set his background wallpaper to get set every couple of minutes, also causing his dock to restart, very closely mimicking the symptoms of a virus…but on a mac. I don’t have any Mac-fu, but I was able to use my linux-fu to make the prank even more devious.

touch -f sourcefile destinationfile
copies the timestamp from one file to another. If you put your prank image in a directory with a bunch of other files, you can help your file blend in by giving it a timestamp that’s the same as another file.

The other trick is to move the file into a folder whose name starts with a . so it is harder to find. While you’re at it, might as well name the file with a starting with a . also.

We stashed the trouble files in his .keepass folder and named them things like .specialkey.

finally, history -c clears out your terminal history so that nobody can see what you have been up to.

Sadly, Katy felt guilty about being so mischievous and left instructions on how to ‘fix’ it, so he never got to appreciate the extra detail we went through to make it tricky to find and fix.

But you can bet he locks his computer now, and he learned how to make his Mac show hidden files.

 
No Comments

Posted in fun

 

Pictures of Grooveshark

06 Feb

Wondering what Grooveshark looks like? OfficeSnapshots.com has pictures of the Grooveshark office.

You can spot my desk if you look for the one with the yellow motorcycle helmet. You can also see the insanely bright reflective glare of my motorcycle jacket, which was sitting on the back of my chair. You’ll note that I was not sitting at my desk when these pictures were taken. Search for the mountain man and you’ll find me.

 
 

OhHai->I->HasA(UPDAET)

04 Feb

As an update to my previous lolcode post, we are fixing the GetGenre()->GetGenre() issue by calling them names. GetGenre()->GetName()

There is talk of adding __toString() functions to classes like Genres and Tags but I tend to not be a fan of automagic functions. __toString() would enable us to just call GetGenre() and if we treat the resulting object as a string, it will call GetName() behind the scenes, and if we treat it like an object it will still be an object. That is a “neat” language feature, but I believe it leads to obscurity and inconsistent behavior in certain cases.

For example, if the object is not directly treated as a string even though it needs to be a string, it __toString() will not be called, and problems will ensue. Confusing problems, because the object acts like a string, sometimes.

sloppy example code:

class notAString
{
    public $what;
    public function __construct($val)
    {
        $this->what = $val;
    }
    public function __toString()
    {
        return $this->what;
    }
}
$whatIsIt = new notAString("a string");
$isAString = is_string($whatIsIt);
$isAnObject = is_object($whatIsIt);
var_dump(array('isAString' => $isAString, 'isAnObject' => $isAnObject));
echo $whatIsIt;

Output:array
'isAString' => boolean false
'isAnObject' => boolean true
a string

It fails the is_string check, so if you pass the object to a function that expects a string, and the function is smart enough to check for a string before doing anything with it, your call is going to fail and you’re going to be scratching your head wondering why.

Now imagine how confusing this would be if you were trying to debug a piece of code that you had no hand in writing, you see this object being used as a string, only you don’t know it’s an object because it’s being used as a string and that part of the cod works. “It should be declared right there, just look and you’ll see it’s an object.” Sure, or it could be passed in from another function and you haven’t looked that far up the ladder yet.

Worse, you finally figure out that it’s an object, and now you can’t figure out why it’s successfully being treated as a string elsewhere. You look at the class and you don’t see a __toString() function. You look at the parent class, no __toString() there either. Ah well, a red herring, time to move on right? Or did you give up before looking at the parent class’s parent? Was there a __toString() there? How much time was wasted trying to find that, compared to how much time the automagic __toString() function might save you as a developer?

I’d wager it’s not worth the lost time, and the added frustration.

 
No Comments

Posted in Coding

 

OhHai->IHasASong()->ICanHasGenre()

03 Feb

Sometimes naming conventions can have weird side effects.

Consider this example:
Our tables and fields are named in CamelCase (or StudleyCaps, or StudleyCamels as we like to call them), this is not my preferred way of naming tables/fields, but it’s what we’ve got so we work with it. We* decided that Genres are entities so the Genres table contains a Genre field which is a VARCHAR.
In PHP we are using our own flavor of ORM that avoids the pitfalls of most ORM systems while keeping the benefits. Our database objects all have Get methods for each object property (which may or may not be a field in the table that the object represents). If you want a song’s Genre, you call Song->GetGenre(), which gives you a Genre object. If you then want the text-representation of the Genre, you have to call…GetGenre(). So if you want, from the Song object, the text representation of the Song’s Genre, you call: Song->GetGenre()->GetGenre()
We might as well have made it say Song->GetGenre()->PrettyPlease() or ->NoSeriously()

At least we aren’t writing our code lolcats style (see: lolcode) or it might look more like the title:
OhHai->I->HasASong()->CanHasGenre()->CanHasGenreNoowwwwwwws()

*actually someone else decided before I ever started working here

Kthxbye.

 
3 Comments

Posted in Coding

 

Auto-query-generator

02 Feb

They say that Computer Scientists aren’t satisfied with putting other people out of jobs; they want to put themselves out of a job as well. In that vein I am writing a function that, given basic information about our database tables and their relationships, can build efficient queries automatically based on a complex filter consisting of:

  • The information requested
  • Any combination of IDs to filter the results based on

For example, you can tell it that you want the names and IDs of Playlists belonging to a user with a certain artist and my function will build the SQL on the fly based on what it knows.
This is extremely useful because I am working on a super secret project* with Katy and her app has no knowledge of hte database but needs to be able to ask for some extremely specific sets of data depending on user behavior. Instead of manually writing N! queries to handle every possible combination of requests, my function does all of the heavy lifting for me.

The code isn’t quite done yet but the code that figures out the join sequence and which key to join on is done, and surprisingly it only takes about 10 lines of code. I still need to add code to handle special cases, and I need to write the code that takes that sequence and turns it into real live SQL so it will surely grow, but that is still far less than I imagined would be required to get this far.

*not actually a secret project, but I haven’t written about it yet and it’s beyond the scope of this post.

 
1 Comment

Posted in Coding, SQL

 

Ask and ye shall receive

01 Feb

I just recently posted a Paul Dateh Video and subsequently flipped out at marketing about how awesome he is.

They pulled through and lined up an interview with him next week. He had even already heard of Grooveshark, so that’s pretty awesome. It will be really cool if we can convince him to come play in Gainesville. Either way look for a post on the Grooveshark Blog next week with the interview.

 
No Comments

Posted in music