The Journalist's Cage

And this gray spirit yearning in desire to follow knowledge like a sinking star...

HomeBlogTagsArticles

Calendar

January 2007
SuMoTuWeThFrSa
 123456
78910111213
14151617181920
21222324252627
28293031

Recent Bookmarks

Tags

Archives


RSS

Simpy and Powershell

I have spent a lot of time lately working with Powershell, Microsoft's next generation command-line environment. Built on the .NET architecture, Powershell is extremely versatile and robust. It provides excellent support for dynamic manipulation of XML content, a feature that is particularly useful when used in conjunction with .NET's Internet functionality.

Earlier this week, I did a bit of experimentation and figured out how to use Powershell to interact with the Simpy social bookmark service. When I developed Ruby bindings for the Simpy REST API, the most frustrating impediment was Simpy's mildly awkward redirect system. Ruby's Net::HTTP class doesn't handle redirects automatically, so I had to manually implement support for handling a 302 response. I also had to manually create the authentication string for the header using Ruby's Base64 encoding library. Powershell handles both of those things automatically. The .NET Net.NetworkCredential object automatically generates the proper header string when provided with login information, and the Net.WebClient object's downloadString method does proper redirect handling on its own without necessitating further intervention.

Powershell handles XML very well, which also made the task much easier. Certain aspects of the XML API seem needlessly verbose or a little bit eccentric. For instance, when you use the select-object Cmdlet to access an element node, it returns the node itself rather than the value of the node in some cases. Based on my own experiments, I think that it fails to show the actual text value when the contents of the node are wrapped in a CDATA block. In order to extract the text value, one must use the get_innerText method.

The following example demonstrates how to use Simpy's REST API from the command-line to display the nicknames and tags of recent bookmarks:

> $connect = new-object Net.WebClient
> $connect.credentials = new-object Net.NetworkCredential("segphault", "XXXXXX")
> $links = [xml]$connect.downloadString("http://simpy.com/simpy/api/rest/GetLinks.do")
> $links.links.link | select {$_.nickname.get_innertext()}, {$_.tags.tag | % {$_.get_innnertext()}}

$_.nickname.get_innertext()             $_.tags.tag | % {$_.get_innertext()}
---------------------------             ------------------------------------
GNOME Journal article about Tinymail    {development, software, email, GNOME...
Comparison of various open source gr... {development, software, graphics, Li...
Agile programming considered (mostly... development
Metaprogramming with Ruby               {Ruby, development, metaprogramming}
Linus talks like a pirate               {LinuxArs, Linus, Linux Kernal, soft...
Mark Shuttleworth talks about Ubuntu... {LinuxArs, Ubuntu, Debian}
Optimal use of fonts on Linux           {LinuxArs, X11, fonts}
IBM to provide commercial support fo... {LinuxArs, Eclipse, IBM}
McDonalds changes McFlurry cups to s... strange
GNOME orphaned thumbnail remover        {LinuxArs, GNOME, Glade, Python...}

Note that the inability to consistently extract the text value of a node with select makes it necessary to use a loop in order to display the tags as a list. If CDATA blocks weren't so troublesome, the select invocation would be a lot more concise. Despite the minor deficiencies, Powershell is well suited for this sort of work.

I also experimented with listing tag information. The following demonstrates how to display a list of tags and the number of bookmarks associated with each tag:

> ([xml]$connect.downloadString("http://simpy.com/simpy/api/rest/GetTags.do")).tags.tag

name        count
----        -----
LinuxArs    42
software    22
GNOME       8
strange     6
Mono        5
science     4
Qt          4
...

If I can find some time for further experimentation, I might throw together a few Powershell Cmdlets to automate link and tag manipulation.


Posted on 2006-09-300 comments



My Blog Works Again!

I finally managed to set aside enough time to fix my blog. The frustrating limitations of PyBlosxom compelled me to search for better solutions, but I was unable to find blog software that meets all of my needs. Rather than attempting to integrate new features into an existing code base, I decided to write my own from scratch. Although I generally try to avoid reinventing the wheel, starting from scratch with Ruby ended up being less labor intensive than trying to fix PyBlosxom, and I will thankfully be able to maintain and extend my new system with much greater ease.

Although I still use nested categories under the hood, my new system emphasizes tags. Categories are poorly suited for blog entry classification, and tags provide a much higher level of flexibility. Consider my previous entry about the Vim Ruby bindings, for instance. Does that belong in the Software/Vim category or in the Programming/Ruby category? With tags, I can associate the entry with Programming, Ruby, Software, and Vim. Tags also facilitate some very intriguing and useful navigation paradigms. I'm particularly pleased with my new tag cloud feature, which displays tags in various sizes and colors based on frequency of tag use. For those of you that are not familiar with tag clouds, a brief description can be found alongside the clouds on my new Tags page.

I have also integrated Simpy functionality. The Recent Bookmarks section on the left is populated entirely from Simpy using my Ruby API. Despite my initial skepticism regarding social bookmarking, I have become an avid user, and I am now convinced that the concept is brilliant. My Tags page displays an additional cloud with tags from Simpy links. Unfortunately, the Simpy REST API does not provide temporal details for tags, so my script has to do some very inefficient processing that places excessive load on the Simpy servers. In order to limit the impact of that load, I have configured my script to cache the data and generate new tag clouds only when I add or update a blog entry. I plan to discuss this deficiency with Otis, one of the Simpy developers. Otis has been very receptive to my constructive criticism in the past, and I think that he will implement the features I need to make an efficient implementation of my Simpy tag cloud generator.

In addition to tags, I also implemented support for custom syndication exports. Now that I have a working blog, I would like to be able to add it to Planet ArsLinux and eventually Planet GNOME. The syndication export feature will enable me to control which entries get exported to various planets. I would also eventually like to create a Planet Cixar which will include the blog entries of all developers working on Cixar projects.

At present, my entire blog system (including the cloud feature) is about 300 lines of code. It is still too messy for public exhibition, but I plan to clean it up for official release at some point in the next few months. For those that are interested and impatient, private requests for access to the source code will be granted in the interim. The tag cloud code may be released sooner, because I think it would make a fun topic for an article. During the development process, I experimented with several different libraries and frameworks. I wanted to use Ruby's CGI library, but unfortunately, it doesn't support XHTML. I eventually found a nice patch that adds reliable support for XHTML 1.0, and I applied it to a copy of the Ruby 1.8 CGI library for deployment with my blog script. The CGI library has some particularly useful features for generating output and parsing parameters. I also started experimenting with WEBrick, a light-weight Ruby server that was immensely useful during the debugging process.


Posted on 2006-07-171 comments



Social Bookmarking

I have recently developed an interest in web services that enable users to store and share links on the Internet. Social bookmarking services are increasingly popular amongst bloggers, and could completely replace conventional bookmarks as ubiquitous broadband becomes reality. After comparing a number of available services, I finally settled on Simpy, which has several unique features and provides numerous advantages over competing services like del.icio.us. I'm particularly impressed with Simpy's support for third party development. Using the Simpy REST API, I can manipulate my bookmarks with virtually any programming language.

Although I initially had some problems with the authentication mechanism, I eventually managed to create a complete Ruby library for interacting with Simpy. Now officially released, the source code is available online through the Simpy Tools Sourceforge version control system. Documentation for the latest CVS version can be found here.

At the present time, simpyapi-ruby features support for adding, removing, modifying, and acquiring links as well as removing, renaming, and listing tags. Support for notes and watchlists will be implemented in a future version. Unsupported operations can still be performed with the generic Simpy::ClientBase.command method. Support is also provided for interfacing with Simpy RSS feeds.

The simpyapi-ruby library allows developers to leverage Ruby's syntactic sugar and interact with Simpy without having to parse, process, or manipulate XML data. Login and connection handling is all automatic, all you have to do is provide simpyapi-ruby with a Simpy username and password.

The simpyapi-ruby library is very easy to install. Simply run the setup.rb script included with the library. The library was designed with application development in mind (I plan to create a proof-of-concept GNOME utility for Simpy management), but it is also entirely suitable for simple scripting and web integration. For optimal exposure and licensing compatibility with other Simpy tools, my library is dual-licensed under the terms of the ASL and BSD licenses.


Posted on 2006-06-210 comments