RSS
 

Archive for the ‘Uncategorized’ Category

Use memcache better

30 Jun

I believe I have already mentioned a couple of times how memcache makes Grooveshark Lite possible.

Well, while implementing memcache for Grooveshark Lite, I ended up making a wrapper class called GMemcache for lack of a better name, which inherits from the PHP Memcache class, adding on just a few cool enhancements:

1. Singleton. Has static variable $instance that is set in the constructor and is also available in a getInstance() method.
2. Disable-able. Integrating with memcache can involve writing a lot of memcache-specific code, which means it can be quite a pain if you then need to temporarily disable memcache for some reason, such as testing. We define MEMCACHE_DISABLED to true when we wish to have our code bypass memcache altogether. The class wraps get, set, etc., and if memcache is disabled returns false for get (equivalent of saying “I couldn’t find it”) and doesn’t do anything when set is called. otherwise it calls parent::get etc.
3. Version-able. We also define an app version, which is then automatically appended to all keys. That way new releases never get stale data (or worse, data in a different structure from what it expects!). For situations where versioning does not make sense, set, get, etc all take an extra boolean parameter which indicates whether versioning should be skipped (defaults to false).

The nice thing about inheriting from Memcache this way (as opposed to having a Memcache instance as a member variable) is that we don’t have to rewrite all of the functionality. Whatever parts we do not need to change or do not care about, do not have to be written and they will continue to work when accessed via GMemcache.

 
 

How not to do SOAP

24 May

If you are not already familiar with SOAP, this note will mean very little to you, and I don’t feel like explaining it so please feel free to ignore.

We are in the middle of adding a new payment processor to GS, and this particular payment processor, who shall remain unnamed, decided to implement their API in SOAP. I am not a huge fan of SOAP, but it certainly does have some level of usefulness: the entire backend API for GSLite is written in SOAP, after all. Anyway, their implementation of SOAP is the silliest I have seen so far. Every method takes a single parameter. It’s a string named ixml.

Can you guess yet what they are doing?

Yes, every parameter is a piece of xml. The actual structure of the xml message is not defined in the WSDL. In other words, the Web Service Description Language does not describe the web service. Good job, guys.

 
 

Linux: run script as a different user

22 May

In all the years I’ve been using Linux just enough to get by, I’ve never stumbled across this handy tip. If you have a script that, say, needs root access, but must be executable by users who do not have root access, rather than setting up sudo and then making everyone have to remember to type sudo before they type the path to the script, you can do this:

chmod +s filename

The script will run as the owner, and the permissions for executing the script will be determined by group membership. If you have a script that must be executable by users in the ‘devs’ group, but it must run as root, all you have to do is:
chown root.devs filename
chmod +s filename
(assuming your file is already group executable)

Obviously this file should not be group writable or you’re giving everyone in that group the power to run anything as root, simply by modifying the script and then running it.

 
 

Bad design

09 May

Bad design is everywhere, and it doesn’t have to be that way. I suppose that’s why I make such a fuss when one of our products or features seems to be poorly designed. I want to do better!

Here’s an example of bad design that isn’t our fault:
Everyone in the office has trouble using the coffee pot at one time or another. People get grounds in the water reservoir, overflow the basket, or get burned by steam when they open the lid. I have witnessed people do all of these things, and I have studied the design of the coffee pot. I understand how it works, but I still managed to overflow the basket myself, creating a horrible mess and (worse) delaying my caffeine intake. Why is this coffee pot so hard to use? My cheap coffee pot at home works just fine. I had no difficulties with the coffee pot at my previous job.

It’s the design. The basket and water reservoir are in the same “compartment”, covered by the same lid, and the component that stops the flow of coffee if the carafe has been removed (so you can pour a cup before it’s finished) is a mechanism that is half in the basket (spring loaded stopper) and half in the lid of the carafe (the shape of the lid pushes up the spring, allowing water to flow).

Every element of the design of this coffee pot is directly related to the ways that people manage to mess up their coffee:
If they are not careful about adding coffee to the basket, they will get grounds in the reservoir. The proper way to avoid that problem is to remove the basket, add the coffee and put it back in. The basket does not sit evenly on the counter because of the spring loaded mechanism on the bottom, so it discourages people from adding grounds this way.
Having one lid that covers the reservoir and the basket causes steam to be trapped in the coffee maker, so if people open the lid during the brewing process (say, because something else is messing up) or shortly afterwards (say, to clean up), they will have their fingers burned.
The spring loaded stopper does not stop the brewing process, only the dripping into the carafe process. If the stopper remains closed, water and grounds will eventually overflow the basket into the reservoir, into the carafe, and all over the place. The stopper remains closed whenever it is not in contact with the lid, so if someone accidentally leaves the lid off, or leaves the lid open “to make sure nothing gets in the way” (as one of our interns did), it’s an instant mess complete with ruined coffee.

Compare this to my coffee maker at home, the water reservoir is completely separate from the basket, which swings out on a hinge so that any spilled coffee grounds end up on the counter, not in the water. The mechanism that stops the drip process when the carafe is removed is a small lever that is depressed when the carafe is placed in the coffee maker. It stops the flow of hot water into the basket, thereby halting the brewing process whenever the carafe is removed.

This is an ideal design in every way, especially the lever to stop the brewing process. The only component required to let the water flow is the carafe, which catches the brew. If the carafe is not present, no coffee is brewed and no disaster ensues. Use of a lid is entirely optional.

So why is our coffee pot so horribly designed? It’s not like coffee pots are a new technology, and it’s not like they’ve just been this lousy all along, my coffee pot is older! They could have just copied the design if they couldn’t think of their own. I don’t see how the manufacture of my coffee pot style would be any more expensive than the one we have at Grooveshark. Mine was under $10, after all.

The only thing I can think of is that manufacturers just plain and simply do not care about usability for these essentially disposable appliances. Customers do not pay attention to these details until it’s too late, or they blame themselves for their inability to use them, so good design just does not matter.

But design does matter if your company is not satisfied with mediocrity. One need not look any further than Apple to see the result of putting a heavy emphasis on design and usability. The success of the iPod and iPhone are the direct result of that emphasis. If the iPod worked like a Sansa and the iPhone worked like my old Motorola phone, where would Apple be right now?

 
 

Digsby

06 May

This is just a quick plug for an chat client I’ve just recently discovered: Digsby.

Digsby is a chat client that works with every network they can get their grubby little hands on. AIM, ICQ, Y!, MSN, Google Talk, Jabber, even Facebook chat. But there’s more, they also support email and Facebook, MySpace and Twitter. Twitter has always seemed well, rather useless and annoying to me, but having it integrated into a desktop client and on my phone means I might actually use it.

I know what you’re thinking: Trillian does a lot of that. Well, yes, but digsby seems well designed, less clunky and annoying, and ironically more stable, even though it’s far newer and does more.

Another bonus with Digsby is that you create a profile on their site, so when you sign in on another computer, you don’t have to set up all of your accounts again.

 
 

Meet Grooveshark Lite

15 Apr

Well, for better or worse, Grooveshark Lite is up live and running.

Things are a bit buggy because someone thought it would be a great idea to exponentially increase the complexity of our web setup at the exact same time, and it’s already generated a lot of attention, so don’t be surprised if things just stop working intermittently.
All that said, Grooveshark Lite makes listening to music online super easy, you should definitely check it out.

Here’s a more formal description of GS Lite:

What Grooveshark Lite is:
A flash program written with flex that lets you listen to any MP3s we have in our system.
You can search for music or you can navigate through the heirarchy to find music, browsing songs, artists, albums, playlists or genres.
You can play any of the music you find by clicking the play button, the add to queue button, or by dragging it to the queue.
You can save your queue as a playlist.
You can browse your own music and playlists (even if it’s on another computer) by going to My Music.

What Grooveshark Lite is not:
Grooveshark Lite does not have any social networking components, and will not.

What Grooveshark Lite isn’t yet but will be soon:
Some features that didn’t make it into the initial release (tambourine), but will be added very soon:
Playlist editing: We have a slick interface for managing your playlists; in addition to creating playlists you’ll be able to add & remove songs, delete playlists, rename them, add descriptions, etc.
Auto-DJ: build a queue and our recommendation will add new songs to the queue that it thinks you will like.
Share your music: When you make a playlist, you can get embed code to put our player on your site. There’s a tiny version you can stick in a sidebar or a less compact version to fit in a blog post. The widget pulls the songs based on a playlist, so if you want to change the songs on your site, for example, all you have to do is edit the playlist.
Share your music part 2: If you don’t want to embed the player or don’t have somewhere to do so, you can get a link to your playlist that takes your friends to a page with the playlist loaded in the player. For example, my cake playlist will be accessible via: http://{gslite URL}/boxmonkey/cake or you can send your friends to http://{gslite URL}/{username} and they can browse all of your playlists.

Apologies if any of this is incoherent: I’ve been up since 1pm yesterday. AWESOME.

 
 

Busy

26 Mar

As you can see, I’m too busy to write down everything that’s floating in my head this week. Hidden on this blog somewhere is a cryptic clue as to why that is.

In the meantime, keep busy with this great rant from Chanel: I Want My Music.

 
 

grooveshark peer offline

24 Mar

I noticed that someone found my blog by searching for “grooveshark peer offline” recently. Apparently that error message is not clear enough, so I’ll try to explain some of the causes of that message. This may not be an all-inclusive list because I’m not directly involved with a lot of the things that cause this problem, but common causes for that message include:

We showed the file as being online even though it wasn’t really (that shouldn’t be happening anymore; it’s the only part I have control over).
The peer said it had the file, but when we tried to access it, the peer said it didn’t have the file.
The peer was flagged as being online, but when we tried to connect to it via the supernode it’s supposed to be connected to, the supernode said that the peer was not connected.
The peer refused the connection (usually happens when people have firewalls and such turned on).
The NAT type of the peer was not compatible with your NAT type. Unfortunately because of the style of communication used by the clients, it’s possible for two peers to both be online but unable to communicate with each other due to incompatible NAT types. There’s no easy fix for this, but eventually we will enhance the site so that users with incompatible NAT types show up as being offline.

If you are getting lots of “peer offline” error messages, then there might be a more serious problem. Contact me and I will get you in touch with the people who can diagnose and solve your problem.

 
 

Use Grooveshark faster: Firefox 3.0b4

21 Mar

Right now, Grooveshark is slow. There’s no getting around it; pages take a while to start loading, and then take a while to render. We are in the middle of overhauling the backend which should make a huge difference in the time it takes for a page to start loading, but we PHP/SQL devs can’t do much about render times.

Fortunately, crossover Javascript/PHP developer Chanel has been up to the task and has made major improvements to page rendering times. I can’t even begin to explain why the site can be slow to render, but I know that much of it is Javascript related, and it has to do with the number of elements on the page. But even with Chanel’s genius tricks making the site render 4-5x faster, it still feels sluggish to me.

Well, it happens that the front-end is under an overhaul as well, but I recently discovered something else that makes the site much more pleasant to use: Firefox 3.0b4. One of the improvements listed in the release notes was faster Javascript execution. They certainly weren’t kidding! It makes it hard to go back to using Firefox 2.

So far I have not been terribly impressed with the much-touted memory management improvements. Firefox still uses an amazing amount of memory, 122MB (+104MB of virtual memory) with my Grooveshark library page, Chanel’s blog and this wordpress edit window open. The good news is that Firefox seems to be much more aggressive about wiping out unneeded memory usage, but the bad news is that sometimes Firefox seems to hang while it’s frantically deallocating memory (i.e. when closing a tab).

All in all it’s shaping up to be a nice improvement over Firefox 2, and if they can polish up the memory management to give a consistently smooth user experience, it’s going to be an unbeatable browser.

 
 

Listen to SXSW 2008

17 Mar

Want to listen to one song of every artist featured at SXSW 2008, but don’t want to bother downloading the torrent?
It’s all on grooveshark in one convenient location for you.
Enjoy! Or, you know, don’t, if the music happens to suck. I haven’t actually given it a listen yet. It’s 741 songs long.