goldb.org home

AS OF MAY 2008, THIS BLOG IS NO LONGER BEING UPDATED.
Visit the new blog at: http://coreygoldberg.blogspot.com



 Monday, February 25, 2008

Geolocation Mashup To Visualize My Blog Visitors

I just did a Geolocation mashup to visualize where my blog readers are coming from on a particular day. Below is a visualization of my US/Canada visitors from February 14, 2008.

All of the data is based off of IP addresses from my referrer logs.

To see how to do this, check out: http://www.goldb.org/geo_maps

#    Comments [0] |
 Thursday, February 21, 2008

Novell == Suckers?

I bet that interoperability deal doesn't sound so great now.
#    Comments [0] |
 Tuesday, February 19, 2008

Etymology of "Foo"

"Foo" is my favorite word. I use it all over the place. When programming, it is the name of my quick junk files... it is a temporary variable name while i figure out code. We programmers love our foo.

For those that want the origins and etymology, there is a great RFC about it:

http://www.ietf.org/rfc/rfc3092.txt


#    Comments [0] |
 Friday, February 15, 2008
 Tuesday, February 12, 2008

Python - 15 Line HTTP Server - Web Interface For Your Tools

I write a lot of command line tools and scripts in Python. Sometimes I need to kick them off remotely. A simple way to do this is to launch a tiny web server that listens for a specific request to start the script.

I add a "WebRequestHandler" class to my script and call it from my main method. There is a "do_something()" method in the class. You call your code from this method.

All you have to do is launch your script and it will sit there and wait for requests. If the request is bad, it spits back a 404 error. If the request path matches what we are looking for (in this case "/foo"), the code is launched.

Now you have an easy way to call your script remotely. Just open a browser and type in the URL: http://your_server/foo, or call it with a tool like 'wget' or 'curl'.


import BaseHTTPServer

class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/foo':
            self.send_response(200)
            self.do_something()
        else: 
            self.send_error(404)
            
    def do_something(self):
        print 'hello world'
        
server = BaseHTTPServer.HTTPServer(('',80), WebRequestHandler)
server.serve_forever()

(this was adapted from a code sample in "Python In A Nutshell" by Alex Martelli)

#    Comments [1] |
 Monday, February 11, 2008

Python - Terminating Threads - Boolean Flag and threading.Event()

In many programming languages you can't terminate a thread directly.  Python is no different.  Rather than termintaing a thread from the code that spawned it, you just a pass a flag to the thread that tells it to terminate itself.  Typically a thread will run in a loop, periodically checking this flag so it knows if it should continue or not.  To terminate the thread from the outside, you just set its flag to die.

I was using this idiom in Python by setting a boolean flag in my spawned thread.

So a simplified thread class would look something like this:


class MyThread(threading.Thread):
    def __init__(self, num):
        threading.Thread.__init__(self)
        self.running = True
        self.num = num
        
    def stop(self):
        self.running = False
        
    def run(self):
        while self.running:
            print 'hello from thread %d' % self.num
            time.sleep(1)

I just read an old post in comp.lang.python that pointed to a recipe in the Python Cookbook that suggests using threading.Event() rather than a simple boolean flag.

So the thread class would look something like this:


class MyThread(threading.Thread):
    def __init__(self, num):
        threading.Thread.__init__(self)
        self.stop_event = threading.Event()
        self.num = num
        
    def stop(self):
        self.stop_event.set()
        
    def run(self):
        while not self.stop_event.isSet():
            print 'hello from thread %d' % self.num
            time.sleep(1)

They work exactly the same.

I am just wondering what other flexibility threading.Event() gives you, and if there is anything bad about using simple boolean checks to kill threads. I guess I will have to look it up and play around a bit.

#    Comments [5] |
 Sunday, February 10, 2008

External USB Hard Drive From A Bricked iPod

Here is my bricked iPod. It won't even turn on.  It is time to retire it. However, it has a perfectly good 30 gig hard drive inside.  Gotta be good for something, right?

First I crack it open and get a look at the insides.

The Toshiba 2.5" IDE hard drive sits right near the top.

Next, I bought a 2.5" USB external IDE hard drive enclosure.

I installed the hard drive into the new enclosure, and it's all done. Now I have a nice external storage device.

#    Comments [0] |

Rockin' Python 3000 Alpha (3.0a2)

I just installed the latest Alpha of Python 3000.

So far so good...

#    Comments [0] |
 Friday, February 08, 2008

Test Automation Term: Programmatic Testing - One End Of The Spectrum

Programmatic Testing:  A style of software testing where tests are executed without human interaction.

When I say "this test can be automated", I don't mean a computer can magically replace a sapient process to create a useful test.  All test design and methodology is devised using a sapient processes (obviously).  However, testcase generation, data generation, test execution, results analysis, etc, can often be done without human interaction.  This has been described using terms like: "Automated Testing, "Test Automation", etc.  Among some of the more vocal people in the testing community, these terms are considered confusinginaccurate, harmful, or just a cover up for what is actually a non-scripted test

Automated and Manual Testing are not mutually exclusive.  Rather, they are at either end of a continuum.  A test isn't "automated" or "manual".  It falls somewhere on that continuum.  Each step of the process has some mixture of the elements.

I have also heard the term: "Computer Assisted Testing".  I don't like this term because it tries to place a name on the entire testing process.  I am not referring to the entire process, so this becomes confusing talk to me.  I am referring to a style of test execution.

Therefore, to clear up ambiguity of terminology, I now refer to "Automation" as "Programmatic Testing".  This refers to a style of test execution where tests are executed in a non-interactive manner.

I you have a tool, a test framework, a software library, a program/script, functions for checking conditions, or a mechanism for reporting errors and stats, then you are doing a form of programmatic testing.

#    Comments [1] |
 Wednesday, February 06, 2008

C# .NET 2.0 HTTP GET Class

Sending HTTP Requests from a C# program seems unnecessarily hard.  I wrote a small helper class to deal with sending and timing GET requests:
http://www.goldb.org/httpgetcsharp.html

You use it like this:


public class Program
{
    static void Main(string[] args)
    {
        HTTPGet req = new HTTPGet();
        req.Request("http://www.google.com");
        Console.WriteLine(req.StatusLine);
        Console.WriteLine(req.ResponseTime);
    }
}
#    Comments [2] |
 Tuesday, February 05, 2008

Python - Convert Secs Into Human Readable Time String (HH:MM:SS)

Convert a number of seconds into a human readable time string HH:MM:SS

7046 seconds is: 1 hour 57 mins 26 secs, or 01:57:26

The Function:

def humanize_time(secs):
mins, secs = divmod(secs, 60)
hours, mins = divmod(mins, 60)
return '%02d:%02d:%02d' % (hours, mins, secs)

The Output:

print humanize_time(7046)
>> 01:57:26
#    Comments [5] |
 Saturday, February 02, 2008

wxPython Installer on Windows Vista?

Bug Report To LazyWeb:

Has anyone had success installing wxPython on Windows Vista using the binary installer package?  I get a generic Windows error and the install crashes.  I'm running Python 2.5 and trying to install wxPython 2.8 (wxPython2.8-win32-ansi-2.8.7.1-py25.exe)

I have never tried wx on Vista.  Has anyone else encountered this?


Update 03/05/08: the installer now works fine on Vista

#    Comments [6] |