goldb.org home

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



 Tuesday, March 04, 2008

Just Ordered an Asus Eee PC

I just ordered an Asus Eee PC, the tiny portable 7" laptop.  I got the Black 4G Surf model.  I am psyched to get an ultraportable that runs Debian (Xandros) Linux!

I will blog about it if I do anything cool with it.  It comes with Python installed ;)

#    Comments [0] |

Bill Gates Disses Google's GTalk

via Valleywag:

Quote from Bill Gates about Google:

"The Google tools that have tried to do productivity type things, they really don't have the richness, the responsiveness. Most of these Google products, to be frank, the day they announce them is their best day. I remember there was one called G Talk. I can barely remember the name but it was, you know, going to change the world."

Pretty funny comment since I use GTalk all day long and am slowly seeing my contacts fill up with other GTalk users.  I have never used MSN Messenger and never plan to.

#    Comments [3] |

Python - Bytes Received and Transmitted for Windows

This script will output bytes received and transmitted for a local Windows machine since the last reboot:


import re
from subprocess import Popen, PIPE

p = Popen('net statistics workstation', stdout=PIPE)
for line in p.stdout:
    m = re.search('Bytes received\W+(.*)', line)
    if m: print 'Bytes received: %s' % (m.group(1))
    m = re.search('Bytes transmitted\W+(.*)', line)
    if m: print 'Bytes transmitted: %s' % (m.group(1))
#    Comments [0] |

Python - Get Last Windows Reboot Date/Time

This script will output the last reboot date/time for a local Windows machine:


import re
from subprocess import Popen, PIPE

p = Popen('net statistics workstation', stdout=PIPE)
m = re.search('(\d+/\d+/\d{4}.*[A|P]M)', p.stdout.read())
if m: print 'Last Reboot: %s' % (m.group(1)) 

Output:

>> Last Reboot: 3/1/2008 1:51:41 PM





* updated the original script thanks to Ian's comment below

#    Comments [2] |
 Monday, March 03, 2008

Python - Padding Single Digits In Dates

Here is how to zero-pad single digit days or months in a date string:


date = '3/2/2008'
padded_date = time.strftime('%m/%d/%Y', time.strptime(date,'%m/%d/%Y'))
print padded_date
>> 03/02/2008
#    Comments [2] |
 Sunday, March 02, 2008

Python - Palindrome Checker

A palindrome is a sequence that reads the same in either direction.

Here is function I wrote to check if a phrase is a palindrome:


import re

def is_palindrome(txt):
    txt = re.sub('\W+', '', txt).lower()
    return txt == txt[::-1]



phrase = "Go hang a salami, I'm a lasagna hog"
print is_palindrome(phrase)

>> True
#    Comments [4] |
 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] |
 Monday, January 28, 2008

Subway Chat With Richard Stallman

I just took the Subway (the "T" here in Boston) home from work and ran into Richard Stallman.  I saw the big RMS beard flowing and I flagged him down.  The next train was running late so we got to chat for a while about GPLv3 adoption and some other Free Software issues.

It's pretty cool to have a conversation with somebody who has influenced my life and ideals so very strongly.

It wasn't the first time I had met him, but it was the longest and most pleasant conversation I have had with him.

Good stuff!


O'Toole's Corollary of Finagle's Law: “The perversity of the Universe tends towards a maximum”



(no i didn't take his freakin picture today :)

#    Comments [0] |
 Tuesday, January 15, 2008

Farewell Old Laptop

Goodbye my trusty Dell 600M:

You served me well for 2+ years in all your single-core glory.  Thousands and thousands of lines of code.. music.. movies.. entertainment.. information.. communication.

Unfortunately your keyboard broke and this is where we part ways.

You have been replaced by a shiny new Dell Vostro 1500 (Core 2 Duo).

#    Comments [0] |
 Monday, January 14, 2008

Boston Snow Pics - Back Bay Buried

Snow day today in Boston...

They declared a Snow Emergency last night and we are getting dumped on as I write this.

Here are some pics of the Boston city plows and salters/sanders getting going:


#    Comments [0] |
 Wednesday, January 02, 2008

New Year's Resolution

Just ordered a new laptop... so my new year's resolution will be:

1680 x 1050 (WSXGA+)

#    Comments [1] |
 Tuesday, December 18, 2007

The Python Papers - Screen Scraping Article

The new issue of the Python Papers is out.  It includes a small article I wrote called: Screen Scraping Web Pages

The issue can be downloaded here:  The Python Papers, Volume 2, Issue 4 (pdf)

This tutorial shows how to programmatically retrieve a stock quote from Google Finance.  It uses Python's high level Web API and screen scraping with regular expressions.
#    Comments [2] |
 Monday, December 17, 2007

Python Experts - Why They Do Python

I was recently interviewed for the article:
Python Experts - Why They Do Python

I don't think I am even close to an "expert", but it was nice being asked to participate.

#    Comments [0] |
 Friday, December 14, 2007

Technical Skills For Performance Testers

A performance engineer is a little bit of a jack-of-all-trades.  Rather than focusing on small technological niche, performance testers must have a very wide range of technical skills to understand the inner working of a complex system under test.

As far as skill go, Scott Barber has said that you need to be a "mid-level everything":

"Become a "Mid-Level Everything" – Developer, DBA, Network Admin, Systems Admin, Architect, Business Analyst, etc."

If you want to become proficient in analyzing system performance and scalability, there are many technical areas you should study.  Here are some skills I have found to be invaluable in my success as a performance engineer:


Performance Concepts:

  • Methodology
  • Load Generation Tools
  • User/Workload Modeling
  • Results Analysis (Latency, Throughput, Metrics)
  • Bottleneck Detection
  • Code Profiling
  • Scalability
  • Concurrency
  • Charting/Graphing
  • Statistics

Operating Systems and Servers:

  • Monitoring (CPU/Network/Mem/Disk/etc)
  • System Tuning
  • Web/Application/Middleware Server Tuning
  • System Administration
  • Virtualization
  • OS Concepts (CPU Scheduling, Memory Management, etc)

Database:

  • SQL
  • Stored Procedures
  • Monitoring
  • Tuning

Network:

  • Topology
  • Monitoring
  • Load Balancing
  • TCP/IP
  • HTTP
  • Packet Sniffing and Protocol Analysis
  • Caching
  • OSI Model

Programming:

  • Proficiency in at least on general programming language. Preferably a dynamic scripting language (Python/Perl/Ruby/etc)
  • Code/Algorithm Analysis


(Note: There are lots of "soft skills" a performance tester would need to be successful. This post focuses only on technical skills)

#    Comments [2] |