goldb.org home

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



 Thursday, November 23, 2006

SOAP and REST - Conceptually

After reading thousands of articles about SOAP vs. REST, I was more confused about everything than convinced of anything.

Finally, this quote  from Stefan Tilkov made the conceptual difference between SOA(P) and REST very clear to me:
"In REST, you have lots and lots of resources all supporting the same interface; in SOA(P) (at least the wide-spread paradigm), you have few endpoints all supporting different interfaces."

#    Comments [0] |
 Friday, November 17, 2006

Python - The New Choice For Computer Science Academia?

I have seen a few articles in the past couple days talking about how MIT is revamping its introductory computer science course from using Scheme/Lisp to using Python.  Apparantly, other CS programs are using Python as well.

As an undergrad in 1993, I took CS classes in a program that was somewhat modeled after the MIT curriculum.  We used the first edition of the [in]famous wizard book.  Head first into the weird ways of functional programming was a bit of a shock for me and Scheme nearly scarred me for life.  I think the move to using Python is certainly a good one.

I just took a look around the net and was surprised by how many people are pushing for Python as an introductory language that is well suited to be taught in an academic setting.


Some links to related articles:

Teaching with Python
Using Python in a High School Computer Science Program
EDU-SIG: Python in Education
Teaching Introductory Computer Science with Python

#    Comments [0] |
 Tuesday, November 14, 2006

MQSeries and .NET - Interacting With Message Queues from C#

Below is a C# Class that I use for interacting with MQSeries (reading/writing from/to queues). 

It contains 2 methods:
PutMessageOnQueue
GetMessageOffQueue

To use it, you must have IBM WebSphere MQ installed, and you must add an assembly reference to amqmdnet.dll (the .NET bindings that come with WebSphere MQ).

I am using:
.NET 2.0
VS 2005
WebSphere MQ 5.3.0




public class MQSeries
{
    string queueName;
    string queueManagerName;
   
    MQQueue queue;
    MQMessage queueMessage;
    MQQueueManager queueManager;
   

    public MQSeries()
    {
        queueName = "TESTQ";
        queueManagerName = "TESTQM";
        queueManager = new MQQueueManager(queueManagerName);
    }  


    public void PutMessageOnQueue(string message)
    {
        try
        {
            queue = queueManager.AccessQueue(queueName,
                    MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
            queueMessage = new MQMessage();
            queueMessage.WriteString(message);
            queueMessage.Format = MQC.MQFMT_STRING;

            queue.Put(queueMessage);
        }
        catch (MQException mqexp)
        {
            Console.WriteLine("MQSeries Exception: " + mqexp.Message);
        }
    }


    public string GetMessageOffQueue()
    {
        string message = "";
       
        queue = queueManager.AccessQueue(queueName,
                MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
        queueMessage = new MQMessage();
        queueMessage.Format = MQC.MQFMT_STRING;

        try
        {
            queue.Get(queueMessage);
            message = queueMessage.ReadString(queueMessage.MessageLength);
        }
        catch (MQException MQExp)
        {
            Console.WriteLine("MQQueue::Get ended with " + MQExp.Message);
        }

        return message;
    }

}
#    Comments [0] |
 Sunday, November 12, 2006

CPU Monitor With Python And WMI

Tim Golden's WMI module for Python is a lightweight wrapper around the WMI classes available for all Win32 platforms.

Windows Management Instrumentation (WMI) is Microsoft's implementation of Web-Based Enterprise Management (WBEM), an industry initiative to provide a Common Information Model (CIM) for pretty much any information about a computer system.

I will give a simple example of monitoring your local CPU using the WMI module from a Python program.


First, we can explore the WMI Win32_Processor class:

import wmi
c = wmi.WMI()
for s in c.Win32_Processor():
    print s


Output looks like this:

instance of Win32_Processor
{
    AddressWidth = 32;
    Architecture = 0;
    Availability = 3;
    Caption = "x86 Family 6 Model 13 Stepping 6";
    CpuStatus = 1;
    CreationClassName = "Win32_Processor";
    CurrentClockSpeed = 1794;
    CurrentVoltage = 33;
    DataWidth = 32;
    Description = "x86 Family 6 Model 13 Stepping 6";
    DeviceID = "CPU0";
    ExtClock = 133;
    Family = 2;
    L2CacheSize = 2048;
    Level = 6;
    LoadPercentage = 6;
    Manufacturer = "GenuineIntel";
    MaxClockSpeed = 1794;
    Name = "        Intel(R) Pentium(R) M processor 1.80GHz";
    PowerManagementSupported = FALSE;
    ProcessorId = "AFE9F9BF000006D6";
    ProcessorType = 3;
    Revision = 3334;
    Role = "CPU";
    SocketDesignation = "Microprocessor";
    Status = "OK";
    StatusInfo = 3;
    Stepping = "6";
    SystemCreationClassName = "Win32_ComputerSystem";
    SystemName = "GOLDB";
    UpgradeMethod = 6;
    Version = "Model 13, Stepping 6";
    VoltageCaps = 2;
};



Here I use it in a script that prints CPU utilization every 5 seconds:

import wmi
import time

c = wmi.WMI()
while True:
    for cpu in c.Win32_Processor():
        timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
        print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
        time.sleep(5)


      
Output looks like this:

Sun, 12 Nov 2006 19:26:25 | Utilization: CPU0: 4 %
Sun, 12 Nov 2006 19:26:31 | Utilization: CPU0: 8 %
Sun, 12 Nov 2006 19:26:37 | Utilization: CPU0: 1 %
Sun, 12 Nov 2006 19:26:43 | Utilization: CPU0: 6 %
Sun, 12 Nov 2006 19:26:49 | Utilization: CPU0: 13 %

#    Comments [0] |
 Tuesday, November 07, 2006

Python - Removing Duplicates From A Sequence

Sequences (lists and tuples) are common data structures used in Python programming.

Here is a simple function that will remove duplicates from a sequence and return a sorted sequence of the unique items:


def remove_dups(seq):
    x = {}
    for y in seq:
        x[y] = 1
    u = x.keys()
    u.sort()
    return u


(Caveat:  It requires that all the sequence elements be hashable, and support equality comparison)


And another implementation (not sure which is better):

def remove_dups(seq):
    u = [x for x in seq if x not in locals()['_[1]']]
    u.sort()
    return u



Example using them from the Python Interpreter:

>>> my_seq = [1, 1, 3, 1, 2, 2, 7.75, 'foo', 7.75, 'foo']
>>> print remove_dups(my_seq)
[1, 2, 3, 7.75, 'foo']




Tim Peters has an excellent recipe in the Python Cookbook that dives into this much further:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
#    Comments [0] |
 Sunday, November 05, 2006

Dynamic Languages On The CLR - IronPython For ASP.NET

OK... Dynamic Languages on the .NET CLR are getting serious:
(especially Python)

IronPython

... and infiltrating the .NET stack further:

IronPython for ASP.NET

The New Dynamic Language Extensibility Model for ASP.NET

#    Comments [0] |

Extending Copyrights: Elvis Is Not Going To Produce Any More Recordings In 1957

I think most people have a very confused view of what copyrights are for.

As usual, Richard Stallman clarifies this in his simple pointed words:  Misinterpreting Copyright

Further clarification from Larry Lessig:  

"[There is] fallacy in any public policy argument that tries to suggest there is an economic harm from failing to extend the term of an existing copyright. The key is the distinction between social value and individual value."

Yes..  Social Value vs. Individual Value.
I especially love Lessig's quote here about the "tax" (yes, it is a social tax or trade-off) of extending copyrights:

"The work is already produced. No matter what we do today, Elvis is not going to produce any more recordings in 1957. So it is a tax that benefits some plainly, but benefits society not at all."

#    Comments [0] |

Perl 6? The Long Wait

I've been waiting for Perl 6 for quite a few years now...

I initially started hacking Perl in 1998 in my days as a software tester.  Perl is a programming language that tends to be popular with testers... usually because of its powerful text processing features (built-in regex's, dynamic/weak typing, simple/powerful data structures, etc).  It is perfect for munging large data sets and slinging text into whatever test configurations you need.  I have written plenty of useful software in Perl.

But.. the Perl community has sort of stagnated and other languages are taking over what was once its niche  (By stagnated I mean in terms of getting a finished version out, certainly not in terms of work being done.. which there is lots of).  We have been waiting on Perl 6 for many years now and a working implementation is yet to be generally released.  Every year or so, we get a new term or acronym to chew on (Parrot, PONIE, PUGS), but day to day I write less and less Perl as other languages seem to be moving faster.  I know there are lots of very bright and talented people working on Perl 6... and I appreciate that.  But I get the feeling that it is concentrated in a few individuals.  I wonder why Perl 6 development hasn't scaled like some other languages have?  Other dynamic language communitues (i.e. Python/Ruby) seem to be constantly embraced and pushed forward... and with that comes a healthy community with diverse and active contributors.


#    Comments [2] |
 Thursday, November 02, 2006

NetPlot - Network Latency Monitor - New Release

I just released a new version of NetPlot (minor bugfixes).

You can get a new copy of the program and GPL'ed source code here:  http://www.goldb.org/netplot.html

NetPlot is a network monitoring tool written in Java. It uses your system's ping utility to send ICMP ECHO_REQUEST to a host or device. With each collection, it sends 3 pings to get the average latency. Results are then plotted in real-time so you can monitor network latency.



#    Comments [0] |
 Wednesday, November 01, 2006

Google Code Search - Indexing Source Code Inside Zip Files

I was playing with Google Code Search (search engine for public source code) and I noticed it had indexed some code I released a while back.

I knew the google bot was indexing public CVS and SVN repositories...
But the interesting thing is that I never checked this code into any public repository.  All I did was place a zip file on my webserver and link to it from my homepage.

I searched around a little and found this explaining what it does:

"The two ways that source code lives on the Internet is in archives, things like Zip files, gzip, etc. And then in software-control repositories like SourceForge.net, Google's code hosting, and other places," Google product manager Tom Stocky told internetnews.com.

"We'll be crawling all of that."

Google isn't just going to index the Zip archive files. They're actually going to open up the files and index all the individual files within in.

This is pretty cool.  By doing a Google Code Search you can see the full contents of the zipped source files, as indexed by Google.

#    Comments [0] |

First Post - Using ASP.NET?

This is the first post for the new blog.

I have been doing software development/programming/testing as a career for nearly 10 years.  I have developed several open source applications in various programming languages (www.goldb.org), and I am pretty rooted in Free Software.  Most of my experience has been developing tools using Python, Perl, and Java on Solaris and Linux.  I also have some experience long ago in Shell, Lisp/Scheme and C/C++.

But...
A few months ago I took a new job developing tools for a performance and scalability group at an ASP.  It is total Windows shop... top to bottom.  So this has been a substantial change to me in terms of my daily work enviornment.  There is a very different approach to programming and systems thinking in the Windows world compared to the Unix philosophy.  This, along with a new set of languages and tools for daily use has been a rather abrupt but very interesting change.

Thankfully, my Python is coming in very handy, and stuff like ActivePython, the Python For Windows Extensions, and easy installers of my favorite packages (like Matplotlib) is making it very easy to reuse lots of my old Python code and build some great new stuff.

I have also taken on learning .NET and C#.  I did lots of Java and J2EE work before, so conceptually the system is something I can get my head around quickly.. there are just _lots_ of pieces to learn.

So that brings me to why I used an ASP.NET based blog here.  Well... I am doing a good amount of programming in C# and ASP.NET 2.0 on a daily basis for work and school (I am finishing up a Master's in CS at Boston University and my current/final course is Human-Computer Interface Design with .NET).  So I found some insanely cheap web hosting that runs ASP.NET 2.0.  Then I found Dasblog (written in C# and ASP.NET 1.1), which looked pretty nice and configurable, so I decided to give it a try.  It is open source and I have all the source to play with, and I like the idea of having full control over my blog...

So there you have it.

(p.s. I didn't drink the kool-aid.  I still create GPL'ed software on the side, and contribute to open source tools whenever I can)

#    Comments [0] |