July 25, 2008

Python - Counting Items In A List

Counting items in a list...

Lets say you have a list like this:
foo = [1, 2, 1, 2, 1, 2, 1, 1]
... and you want to count the items in the list, ending up with a dictionary full of items (dict keys) and counts (dict values), like this:
{1: 5, 2: 3}
Here is an easy way to do it:
d = {}
for i in set(foo):
    d[i] = foo.count(i)
got anything more Pythonic?

July 3, 2008

Searching For Your Open Source Code

One cool thing about developing free open source software is seeing where your code ends up. It is satisfying to know that bits of code you wrote end up in other projects and code bases.

There are several online services that index source code from various places like websites and online svn/cvs repositories. It makes searching for my code a breeze. This is also useful for looking up examples of code I have written in the past that I want to copy from.

  • Google Code Search:
    Search public source code for: "corey goldberg"
  • Koders Search:
    Search public source code for: "corey goldberg"
  • Krugle Code Search:
    Search public source code for: "corey goldberg"

  • July 2, 2008

    Twitter API vs. Yahoo Web Services - Performance and Reliability

    I've noticed the Twitter API is very slow and unreliable. Requests often take 10+ seconds to return. Sometimes they timeout with no response at all.

    I put together some monitoring tools to see exactly how slow and unreliable the API really is (when it is even available!). This is obviously not a very scientific test; just a ballpark idea of performance. The monitoring tools are built with Python and RRDTool. To start with, I used a modified version of my rrdpy suite of tools (http://code.google.com/p/rrdpy).

    I ran a test for 2 hours, hitting the API's Test Method every 30 seconds. The tools generated the following time-series graph of server response times:

    The average response was 2.53 seconds, and we see a *lot* of variance in the data samples.

    In comparison, here is the same test run against the Yahoo Search REST API:

    Notice the small variance and the average server response time of 0.186 secs!

    I would be interested in running these tests again in a few months to see if Twitter's API has become faster and more reliable.

    July 1, 2008

    My Website Visitors By Operating System

    Some interesting stats from my web properties.

    Here is the breakdown of Operating Systems for visitors in the past 30 days: