Category: Programming

Up until recently, I wasn’t a big fan of JavaScript, primarily because I was under the impression that it had limited functionality (possibly a result of seeing it only being used for popup windows and the like). Since I’ve started working on some Dashboard widgets, I’ve found tons of resources on doing useful things with JavaScript, including one recent site, script.aculo.us, which shows a number of ways to liven up web application interfaces. Animations like sliding, folding, fading, and even drag-and-drop resorting are all possible with the right JavaScript. If you’re into creating cool web apps (like Backpack), I highly recommend checking it out. Even if you’re not a coder, script.aculo.us is still worth a look, as it’s rather impressive to see some of these things happening in a web browser. I hope this is only the beginning for interactive web applications.

Published on June 23, 2005

I’ve been working on separating and cleaning up the code I use to run the Recent Tunes area of my sidebar so that it may be made into an easily installable sidebar item for any weblog via a PHP include() statement, but have run into a slight snag. The Recent Tunes application doesn’t work in Tiger and has been sold to someone, so I have no “easy” way of getting the iTunes track data to my webserver with no foreseeable hope of it being updated. It looks like I’ll have to come up with my own solution involving AppleScript. However, AppleScript is just not a language I can work with (I can’t live without {‘s!). If anyone could suggest a simple AppleScript that would grab important data from the current iTunes track and make it available to some other scripting language (PHP would be nice), that would be fantastic. I’ll probably end up putting that AppleScript into a shell script using osascript, then formatting and uploading that data with PHP, all run via cron on my local machine. I’m open to other suggestions, though. The only thing I need is the iTunes track data in a computer-readable format uploaded onto a FTP server. The rest I can change the code to fit. When this does turn into a useable project, you’ll surely get due credit.

I’ve also got a name picked out which has no (yes, zero) results on Google right now, so it will be distinguishable from other projects out there. More on that when I have things working again. For now, I’ve disabled that section of my sidebar.

Published on April 30, 2005

I’m working on a small project which will allow you to connect a small LCD to your Mac via USB, and I’m curious if people have any suggestions as to what they would use it for — current iTunes track, unread mail, RSS headlines?

The chip on the left is a Cypress USB interface from Delcom Engineering, and the one on the right is a standard MAX232 chip, which converts signal levels to RS-232 from the Cypress chip. Using these two together, you can send RS-232 data from your Mac, and I’ve connected it to a serial LCD from Scott Edwards Electronics (the most expensive part of the project), and am able to send any data to the LCD, even control the backlight!

I intend to build up a full page about how I did it in the very near future, but I’m still working on the C code which does the work of talking to the USB I/O chip. Right now, though, I’m looking for suggestions of things to implement for the release. If you have a neat idea, post it in the comments. I’ll be working with a 4 line by 20 character LCD, if it helps.

Update: Also, if anyone has a preferred way of getting data to the LCD, post that as well. Would you prefer AppleScript, Python, something else? I’m sure AppleScript will be involved somewhere along the way to communicate with Mac OS X apps, but what about the “glue” between that and my command-line app? I’m partial to PHP, but it’s not used very often as a system-level scripting system.

Published on April 24, 2005

Here is the code that I use to power my Recent Tunes list seen at right. It’s a little messy, but at least commented so you have some clue what each part is doing. The cover_update.php script is what does most of the work. You shouldn’t have to change anything in the amazon folder – that’s all there to talk to the Amazon.com API, which you will need access to. I also recommend Recent Tunes for updating your tracks from iTunes. Note that I use the current tune, not the list of recent tunes, as it makes managing the MySQL database easier and lessens the load put on Amazon’s API (which I imagine has a ~1000 query per day limit). If you have questions about using it, post a comment so that others can benefit from the conversation as well.

Published on March 22, 2005

After using TorrentSpy on Windows for a while, I wanted a Mac version to do some of the same functions. TorrentSpy’s main feature is that it allows you to see the current number of users on a .torrent file in real-time. I was curious how it worked, so with a little traffic capturing with Ethereal, I was able to see that TorrentSpy was contacting the tracker listed inside the .torrent file at a specific address that was similar to the actual web address of the tracker. This special address, I figured, must hand real-time data back to TorrentSpy. After a minute or two of wandering around on Google (have I mentioned yet how much I love Google?), I came up with the protocol to be followed for transforming torrent announce URLs into “scrape” URLs on a Yahoo groups post. With this information, I started doing some coding in PHP to see what I could come up with.

The next problem presented was that of decoding a .torrent file so the information could be pulled out of it. A great open source project called TorrentParse came to the rescue here, as it provides PHP code for encoding and decoding BitTorrent metainfo files. As I would find out a short while later, these libraries are also pivotal in decoding the real-time information retrieved from the tracker server.

The code I wrote has only a small few parts. The first handles the uploading of a torrent file and checks to make sure it is of the required file type. The next partdecodes the given .torrent file with TorrentParse and extracts the announce URL (the address that the BitTorrent client notifies to show the new seed on the tracker). I wrote a small function called makescrape() that transforms the announce URL into a scrape URL per Bram’s post, linked to above. Upon requesting this new scrape URL, you are returned a BitTorrent-encoded chunk of data containing the real-time information about the torrent. Run that through TorrentParse’s decode function, and pull out the data you want to display.

I would post a demo of the code, but I’m afraid it would be automated and/or abused. However you’re free to download the code and try it out. It still needs some work, especially in handling and managing uploads, but it all works well enough to display basic real-time torrent information. It’s not exactly the Mac version I had in mind from the start, but it could be adapted to a Mac OS X widget with a little work. Get the code here. Enjoy.

Published on March 20, 2005