Popular recipes by Kevin Ryan http://code.activestate.com/recipes/users/1654599/2008-02-18T21:49:31-08:00ActiveState Code RecipesDictionary / Class / List Indexes into Database Query Results (Python)
2008-02-18T21:49:31-08:00Kevin Ryanhttp://code.activestate.com/recipes/users/1654599/http://code.activestate.com/recipes/546525-dictionary-class-list-indexes-into-database-query-/
<p style="color: grey">
Python
recipe 546525
by <a href="/recipes/users/1654599/">Kevin Ryan</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>Similar to some other recipes on this site, this script allows you to access results from queries by attribute (eg, row.field_name), by key (eg, row['field_name']) or by Index (eg, row[0] or row[:2], etc.). It is different from other recipes in that it is both light-weight and offers a variety of access methods with very little overhead. Improvements could be made in fetching the query results (ie, right now I just fetchall()), but I'll leave that up to you.</p>
Calculating the distance between zip codes (Python)
2006-04-25T20:40:00-07:00Kevin Ryanhttp://code.activestate.com/recipes/users/1654599/http://code.activestate.com/recipes/393241-calculating-the-distance-between-zip-codes/
<p style="color: grey">
Python
recipe 393241
by <a href="/recipes/users/1654599/">Kevin Ryan</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>I came across the mention of a formula labeled "The Great Circle Distance Formula" that purported to calculate the distance between any two points on the earth given their longitude and latitude points (the reference was in a Linux Magazine article). So, I looked up some information and cooked up a Python version of the calculation. There are references in the code where you can obtain approximate zip code data for free (e.g., if you wanted to enhance your website by adding a "Search within x mi's" feature), as well as references to the GCDF if you have further interest. Enjoy!</p>
<p>04/25/2006 update: I've decided to update this recipe with an object oriented bent where the information is cached once the object is instantiated. I've also added command line access to automatically download the zipcode file from the census website (just use 'python zips.py -d' and it will download a copy to your harddrive under 'zips.txt'). Lastly, I've added some unit testing so that if any future changes are made this will automatically run and tell me if anything pops out as wrong.</p>
Update web to point to dynamic ip (Python)
2004-11-16T22:15:41-08:00Kevin Ryanhttp://code.activestate.com/recipes/users/1654599/http://code.activestate.com/recipes/335890-update-web-to-point-to-dynamic-ip/
<p style="color: grey">
Python
recipe 335890
by <a href="/recipes/users/1654599/">Kevin Ryan</a>
.
</p>
<p>Many users get a dynamic ip address when they sign on to the internet (e.g., cable modem). If you run a server on your home network, you probably know that you can't point a webpage address to that server with a dynamic ip b/c DNS servers need a static ip. However, if you get a home page with your ISP (e.g., users.someisp.com/myusername), this script will allow you to automatically update your home page with a web page that will redirect your users to your dynamic ip.</p>
<p>Run the code whenever you get a new ip address, and your users will always get to see your website. Best part of all - YOU CONTROL YOUR SERVER! You want to add PHP and MySQL support on your Linux server, go right ahead. The sky's the limit :)</p>