Brian Ray's Blog

Painting is just another way of keeping a diary. --Picasso

Wed, 21 Dec 2005

NYC has Transit Strike, Chicago has bigger butts

I am a public transit advocate. I take my fat butt on the "L" to work every day. The other day, I took the bus just to get some real Mexican food. At first, I thought to myself I should be walking. But the fact that a very cool bus driver sung Christmas carols all the way confirmed to me I made a good choice on ridding the CTA.

CTA Chicago Transit Authority has it's problems. But well, at least we are still running. Unlike New Yorkers, who are currently walking themselves due to the labor strike situation--how terrible.

Let's look on the bright side.. no wait, let's look at the underside--the derriere. Many New Yorkers will get some badly needed exercise. On the flip side, Chicago Tribune writer Virginia Groark writes in Does this bus seat make me look fat? that the CTA has recently ordered seats enlarged from 17 1/2 inches to 18 inches.

As for you hard working Transit workers, I know your job is no piece of cake. I really do appreciate the many years you have taken my fat butt everywhere I've needed to go.


Tue, 13 Dec 2005

Python's Whitespace

"There should be one-- and preferably only one --obvious way to do it." -- Tim Peters

Most people who know me know I am fond of Python. The biggest gripe I hear from programmers about Python is it feels restrictive, at first. Although, what I say in return is to think about with other languages how much time is waisted trying to adhere to all the best practices, DRY and Agile and so on, and work with a flimsy language. Some choices should be trivial and treated this way. Also, if your making something for someone else to use, the "how to" should be as self explanatory as possible.

Take whitespace in Python. One good thing about ChiPy is that I get to hear a lot of programmers talk about programming Python. Once a presenter said when he was first placing is Python code under version control he had done some thing really stupid, he said. He said that instead of converting his tabs to space, he checked them into source control as tabs. Now is this so bad? What is wrong with tabs under source control. For one thing, the tab size, three spaces or four... needs not specified.

I still think back to Guido van Rossum's April's fool joke in his blog. But seriously, why are people afraid of white space? And what is the proper way to handle it? Also, why does it seem some editors are so unfit for managing white space? Why are some programmers afraid to work off a restrictive foundation?

It seems to me, I am better off with Python being restrictive much the same way a carpenter feels comfortable with a rigid piece of wood. Through carefully tooling, the wood can be made pliable into whatever you want and without ever hindering productivity or creativity. Although, if you start with a flimsy piece of wood you can not do as much: not as quickly and not as concisely.


Thu, 01 Dec 2005

Computer Lessons

7 weeks is not too young for Maura's first computer lesson:

http://brianray.chipy.org/Maura/mra.jpg

Snakes and more Snakes

Wow, already 122 people have RSVP'd for the Snakes and Rubies conference we are throwing this weekend here in Chicago. And who voted PyCon should not be held in Chicago? Tsk Tsk.

Good job Chipy organizers!


Calculating Longitude/Latitude Distances in SQL

It has been a long time since the "calculating distance on earth" debate. In fact, I was only able to find some notes.

Although, somebody asked for an equivalent in TSQL. I could not do this because I do not have access to this type of database server. Although, I am running PostgreSQL in a couple of locations and dug up this stored procedure (in plpgsql):

CREATE OR REPLACE FUNCTION zip_distance(integer, integer) returns float4 as '
 DECLARE
   zip1                alias for $1;
   zip2                alias for $2;
   v_zip1               integer;
   v_zip2               integer;
   longitude1          float8;
   latitude1           float8;
   longitude2          float8;
   latitude2           float8;
   delta_lon           float8;
   delta_lat           float8;
   temp                float8;
   dist                float4;
 BEGIN
   v_zip1 := zip1 ;
   while longitude1 IS NULL LOOP
      SELECT longitude_rad, latitude_rad INTO longitude1, latitude1 FROM zip_loc WHERE zip_code = v_zip1;
      v_zip1 := v_zip1 + 1;
   END LOOP;      

   v_zip2 := zip2 ;
   WHILE longitude2 IS NULL LOOP
      SELECT longitude_rad, latitude_rad INTO longitude2, latitude2 FROM zip_loc WHERE zip_code = v_zip2;
      v_zip2 := v_zip2 + 1;
   END LOOP;

   delta_lon := longitude2 - longitude1;
   delta_lat := latitude2 - latitude1;

   temp := pow(      sin(delta_lat/2.0::float8), 2.0::float8) 
            + cos(latitude1) 
            * cos(latitude2) 
            * pow(   sin(delta_lon/2.0::float8), 2.0::float8);

   dist := (3956 
         * 2 
         * atan2( sqrt(temp),sqrt(1 - temp)) )::float4;

   return dist::float4 ;

 END;
' language 'plpgsql';

zip_loc was a lookup table of zipcode longitude and latitudes. Actually, the final code used databases from US Census along with a modified version of the above (rewritten in Python), to find distances between street addresses. Also this data may have been cross referenced with USPS data. I no longer work on this project although I believe it is still in use.

If I remember correctly, this equation got me in some trouble with my meteorologist friends, Michael Tobis. Still, it's crazy fast and does the trick.