Archive for the 'Code' Category

Firefox 3.5 beta 99 – Get Multitouch Gestures Back!

31firstrun-robobg

I just updated to the newest beta of Firefox 3.5 and it’s apparently beta 99. This is pretty funny because the previous one was 4. I think it’s just an indicator that they’re pretty close to a release candidate.

One thing I really like about Firefox (at least these beta versions) is that they support multitouch gestures on my Macbook Pro. Pinching zooms out, un-pinching (spreading?) zooms in, three finger swipe up goes to the top of the page and three finger swipe down goes to the bottom. This is really cool.

One of the weirder ones is that twisting with two fingers lets you go back and forth between tabs. I thought it was wacky at first but now I think it’s very useful. For some reason, the default value for this gesture is disabled in the newest version (beta 99). It’s also disabled in Shiretoko, the nightly build. I tried looking in the preferences to control this but they weren’t in there. Then I remembered about:config.

To get the twist thing back, type “about:config” into the address bar. Then find the settings that say “browser.gesture.twist” The setting for “browser.gesture.twist.left” should be “Browser:PrevTab”  and the one for .right should be “Browser:NextTab” like so:

picture-6

Voila! Your twisty tab changing gestures will be back!

Shuffling and Randomizing Algorithms for Music Playlists

picture-4

I’ve been messing around with iTunes and the DJ functionality. It seems like all it does is pick random songs out of the library and shows them in the order they’ll be played (unlike shuffle, which just randomly jumps around). Typically, I like to put my iTunes library on random when I’m listening. This allows me to hear a bunch of different music in my library. If I don’t like a certain song, I’ll skip it, unless I’m not really paying attention.

I find that the most important piece of metadata in my iTunes library is probably “play count.” This is a pretty good indicator of how much I like a song. It’s a bit off sometimes though, since I might really like a new song with a lower play count because I haven’t had a chance to listen to it 80 times. I use a smart playlist that sorts on “play count” to determine which songs to stick into my iPhone on sync since the phone can’t hold my entire music library. Generally it works well. Perhaps there could be another measure like “normalized play count” that takes into account how long the song has existed in my library.

The iTunes DJ is pretty lacking in terms of how you can weigh what will randomly show up next. You can basically click a box that says “play higher rated songs more often.” I don’t rate my songs (the metadata gets thrown away pretty quickly as I move from computer to computer or Mac to PC, etc), so this feature doesn’t do a lot for me. I prefer the implicit rating (play count) versus the explicit rating (star rating) because the implicit way to do it is natural and doesn’t require me to do anything extra.

I’d like there to be a “play songs with a higher play count more often” feature. This could be bad, though, because it’d lead to a sort of rich get richer deal. So weighting would be important. I’d say it’d be a good heuristic to give each song a probability of “(playcount + 1)/(total number of library plays + # of songs)” to be played. That way the more popular songs (the ones I like more) are played more often, but other songs still have a chance to be played as well (and skipped). There might be other better algorithms for weighing songs based on play count that don’t lead to an unnatural skew (which would mess up the point of having the feature in the first place).

Another thing I could do is prune all of the songs I skip most out of my library. I’m too much of a digital packrat to do that, though, so I guess a smarter algorithm will have to suffice.

Yahoo’s HackU Event at the University of Michigan

hackuheader

I sorta participated in the HackU event that Yahoo sponsored at my school. I say sorta because I got back in from SXSW on Tuesday night (post about that forthcoming) and missed the kick-off. First off, I gotta say something about the name. HackU. Is that like a pun on something?

Anyway, on Wednesday the Yahoo guys went over some stuff on semantic web, search monkey and BOSS. Apparently, the customized search results are the “carrot” on the stick for content producers to markup their content semantically. The Yahoos noted that the customized results provide better click-through rate. While that’s a nice way to think about incentivizing the semantic web, I see a few flaws.

First off, the increased click-throughs are probably due to the pretty graphics and stuff. What happens when everyone has customized search results? The search results page gets cluttered and looks like crap. Furthermore, an increase of click-through in a search engine that has 20% of the search engine market (says Comscore… the numbers for my sites are more like 2-3%) is not much. In my case I’d probably be better off spending my time doing other SEO stuff for Google. Yeah, this is kind of harsh to say (I didn’t say it to the Yahoo guys’ faces) but it’s also realistic. Honestly, I do hope search monkey and BOSS end up being successful, for Yahoo’s sake. As far as swag goes, I picked up a brown Search Monkey shirt on the way out. Oh, and they served some tasty Indian food.

Anyway, I missed the Yahoo events on Thursday. Apparently they did some presentations, then went to a bar. Instead, I had fun at the video game archive and my student org, SCSI. Then on Friday, the 24-hour hackathon thing started. I got there at 4pm and ate some food (it came in waves, burritos, pizza, snacks, Red Bull, soda, etc). They had a different shirt this time, a black one with a wizard on it!

I started trying to figure out what to hack on and came up with an addition to a site that I’ve slowly been working on, What is Hung Doing? Note to self: I think I need to write a blog post on WiHD as well. Basically, I thought it’d be cool to add my location to the site (I was hoping that Google Latitude would be able to do this but I guess it doesn’t offer an API). I used Fire Eagle and the iPhone app called Sparrow to update my location. To grab the location I just made a new application on my server. I dunno the best way to present this info. I’ll fix it up later.

I got the location stuff working and promptly decided to go home around 2am. No 24-hour hacking for me. On Saturday (today), I got up and ran some errands. I bought groceries and got a haircut, then raced back to the CS building on North Campus to do my presentation for WiHD. There were some really neat hacks that were shown off today. One of my friends from the School of Information even won 3rd place. I ended up with a novelty award: “Wannabee Internet Stalkee” or something like that, because WiHD basically enables stalkers. But hey, if it keeps them online instead of around me, then it’s okay, right? Finally, I picked up my final shirt (It has a dragon and a kung-fu guy on it) and went home, along with my award:

hack-u-award

Not too bad for just hacking away at my own project. It’s nice to see Yahoo come and show some goodwill to our school, especially since they skipped out on the career fairs this year. I wonder if they’re even hiring. Either way, I got three shirts, an official Yahoo Faceball, a random puzzle ball and an award, so I’m pretty happy.

Checkin’ Out XSLT

So at work, I’m trying to figure out a good way to make some web pages extensible and also extremely easy to edit. Basically, the people in charge need to be able to make new pages and edit the existing ones when I leave. I was trying to figure out how to do this without a CMS. Because I can’t just throw a CMS into the web server.

I have a friend who wrote something for his portfolio that involves making an xml file, then using the xml to make an HTML page. I was curious to see if this was some kind of common paradigm, and if so, if there were frameworks I could use. The ideal situation would be if I could just set up some XML schema for people to fill in content and then somehow create the HTML from that. Then whoever was updating it would just update the XML (which would be fairly easy since they wouldn’t worry about markup, just the data).

I came across another old friend’s framework, Onion ML, while searching for a solution. It’s pretty funny that I went to undergrad with this guy but just found his site by looking up my own keywords. The Onion ML thing led me to XSLT, which seems to be the solution to my problem.

Apparently XSLT is a way to transform XML into HTML (or something else that’s useful). Unfortunately, XSLT seems a bit more complicated than I was hoping. It looks like the style is defined in one file, then the XML is in another, then there needs to be a way to smash the two together (at running time). I guess there are ways to do this using javascript but I haven’t gotten that far yet.

So what’s the point of this post? I dunno. Probably just to document my thought process on how I got this far. Next step is to see if XSLT can make the job easier or make it needlessly complex (it seems to be a technology that was popular in the early 2000’s, if all these Google searches are correct).

DOM Vs. SAX: Only One Will Survive

So while working on iPhone stuff, we used a SAX parser to handle xml. I thought this was a wacky way of parsing stuff, and I prefer DOM since it is much easier to understand as it’s conveniently in tree form.

Today, I tried parsing a 39mb xml file with Python’s minidom. Bad idea. It’s currently making my MacBook choke and it also made my desktop PC cry for memory. Apparently SAX is 1337 when it comes to memory efficiency while DOM is incredibly inefficient. Seriously, Python was taking more than 1gb of memory to parse a 39mb file! Perhaps my actual use of the minidom stuff was incorrect, but either way, I’ll probably try doing stuff in SAX if the file happens to be even remotely big.

Lesson learned!

Update: SAX totally pwned those large files. All 8 of them! And in less than a minute!