Skip to main content.
October 31st, 2007

Python - How to Catch sys.exit()

I wanted to catch a sys.exit() call in my code (using Python 2.5) and handle it but alas even this wasn’t working:

import sys
try:
    sys.exit()
except Exception,Err:
    print 'hi'

It would just exit the script.

I found this is the way to go when you truly want to capture all exceptions:

try:
    sys.exit()
except BaseException,Err:
    print 'hi'

Please correct me if I’m missing anything. Are there any exceptions I still won’t catch?

Posted by Greg Pinero (Primary Searcher) as Python at 9:58 PM MST

5 Comments »

October 28th, 2007

Winamp - How to Display Song Rating in the Playlist

I had solved this problem a year or two ago, but when I accidentally blew out my winamp install a month ago or so, all my plugins came back, but my media library was gone (along with custom views, etc) and my beloved ability to view song ratings in the playlist. Long story short…Winamp 5.5 (can’t vouch for older ones, but probably everything over 5.0?)

Preferences >> General Preferences >> Titles

In the advanced title formatting section, (assuming it’s already turned on) add the following string…

$repeat(*,%rating%)

This will put as many stars for the rating after whatever else is displayed in the playlist. For instance

Weezer - Only In Dreams *****

Britney Spears - SomeSong *

Now, as to why I have Britney Spears’ songs on my computer is another Answer My Searches post entirely.

Posted by Jody as Other at 11:51 AM MST

Comments Off

October 27th, 2007

Mini Searches with Answers

These are links associated with recent searches I’ve done. They’re not difficult enough to warrant to their own posts but still super useful.

favicon.ico Generator
this looks like a fresh, compelling favicon editor/creator. Try it out.

Python - How to view request message sent from urllib2
Here is how to do it for the simple case:

opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
urllib2.install_opener(opener)

But for using the HTTPBasicAuthHandler I had no clue, so I temporarily just hard coded debug levels in urllib2

Validator that tests whether an XML document matches an XSD document
You upload your XML file and your XSD (XML schema document) file and it tells you whether your XML validates to your XSD.

The softlimit program
softlimit runs another program with new resource limits. This might work when /etc/security/limits.conf doesn’t. I think limits.conf only works for logged in users?

friendsnippets.com - Snippet: A function to enumerate the items of a set product.
Example:
>>> list(enumerate_set_product([1,2],[1,2]))
[[1, 1], [2, 1], [1, 2], [2, 2]]

VectorMagic
This site traces bitmap images, turning them into beautiful vector art. Just upload your image and we will convert it for you.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , ,

Posted by Greg Pinero (Primary Searcher) as Uncategorized at 3:30 AM MST

Comments Off

October 17th, 2007

Baseline Web Page Testing using Curl

I wanted a way to compare the page load times of my website on the old server and on the new server where I’m moving it.

I found an easy way to do this is to use curl. I was inspired by this article, but I improve on it by providing examples that work!

Here are the steps to getting a nice tabular file that shows load time information across a series of URL’s. (Only tested on Ubuntu.)

First I installed curl:
sudo apt-get install curl

Next I made a file called test_config.txt. Here are the contents:

-A "Mozilla/4.0 (compatible; cURL 7.10.5-pre2; Linux 2.4.20)"
-L
-w @logformat.txt
-D headers.txt
-H "Pragma: no-cache"
-H "Cache-control: no-cache"
-H "Connection: close"

url="http://foo.com/"
url="http://foo.members.linode.com/"
url="http://foo.com/utility/Text_Diff"
url="http://foo.com/"
url="http://foo.members.linode.com/"
url="http://foo.com/utility/Text_Diff"

The inspiration article explains a bit about what’s going on here.

Next I made a file called logformat.txt which you can see is referenced in test_config.txt above. Here are the contents of that file:

\n
%{url_effective}\t%{http_code}\t%{content_type}\t%{time_total}\t%{time_namelookup}\t%{time_connect}\t%{time_starttransfer}\t%{size_download}\n
\n

Again the inspiration article explains a bit about what’s going on with this.

Finally we’re ready to run curl. The trick here is that curl insists on outputting the contents of the web pages along with the statistics we want so we pipe it through grep as so (I’m assuming you’re in the directory with the files we just made.):

$ curl -K test_config.txt | grep -i -r "^http://.*$" >> final_output.txt

This whole command runs curl using our configuration files, passes the output to grep, which then pulls out only the lines starting with http:// and outputs that to the file final_output.txt.

Posted by Greg Pinero (Primary Searcher) as Ubuntu at 11:30 PM MST

Comments Off

October 14th, 2007

Mini Searches with Answers

These are links associated with recent searches I’ve done. They’re not difficult enough to warrant to their own posts but still super useful.

Ubuntu Server Guide
This is supposed to be an excellent and thorough guide for setting up an entire Ubuntu server.

IIS.net : FastCGI Extension for IIS6.0 and IIS5.1 - Go Live : Download : Microsoft Internet Information Services
Wow, a fastcgi for Windows. I hope it works with Python. I’m going to try it soon.

Generating and working with GUIDs in .NET - Program - .Net - Builder AU
To make a GUID in C# just call:

System.Guid.NewGuid().ToString();

… I hope

Tim Golden’s Python Stuff: Win32 How Do I…?
Really useful Python windows tasks such as catch system wide hotkeys, lock a workstation, see if a workstation is locked, show mapped drives, and lots more. Yay!

Map Any Key to Any Key on Windows XP / Vista :: the How-To Geek

Digg - LINUX: Securely deleting files with shred
This command might work for journaled filesystems like reiser, and ext3. (use at your own risk)

cat /dev/urandom > DELETEME ; sync ; sleep 1 ; rm -f DELETEME

Tags: , , , , , , , , , , , , , , , , , , , , , , , ,

Posted by Greg Pinero (Primary Searcher) as Uncategorized at 3:30 AM MST

Comments Off

« Previous Entries