Archive

Archive for the ‘Scripting’ Category

Python @SBP

December 17th, 2010 No comments

My first encounter with python was the embedded scripting engine inside XBMC. The code that came with some of the XMBC add-ons sparked my Python interest to the extent that I picked up a couple of O’Reilly books on the topic and started learning the language.

When I joined Schuberg Philis, a few colleagues had Python skills, but Schuberg’s Python community was too small to ensure maintainability. This didn’t stop me from writing a couple of scripts in places where it made sense to use Python, like automating tasks in a Websphere environment using Jython (no, there is no Jerl ;-) ) and in writing one-off scripts where maintainability was not an issue. As a friendly language advocacy, some of the other engineers jokingly referred to Python as being “Perl for Germans”.

In the meantime more Python enthusiasts joined the company, resulting in more and more useful Python stuff being developed, checked into the repositories and actually being used on a daily basis. This including tooling for:
- Weblogic deployment
- Patch management on RedHat systems
- Reporting on incidents
- etc, etc.

So, all things considered, an in-house Python training looked like a good idea. Based on a one day Python training by Steve Holden I took at LISA2008, we approached Steve for a 2 day on-site training at Schuberg Philis HQ. So last week, this actually happened and about 10 of us joined the training.

After going through the python language features (datatypes, mutable vs immutable, namespaces, assignments, staments, functions, exception, modules, OOP, re module), we spend the last afternoon of the training in a free format discussion, touching an a lot of interesting topics like:
- iteration protocol an generator functions
- Pickling, marshalling and shelving objects
- Kodos, regular expression build and test tool
- Multithreading vs multiprocessing
- Network programming
- Unit testing

Everyone took something different away from the training. Some of my gems are:
- “Pyton Module of the week”, which has picked up a new subscriber
- the fact that there is an XML element tree in the standard library (which saves me from installing LXML all over the place), which was not covered in the 2.2 based “Learning Python book”.

The training was great and has certainly broadened as well as deepened our Python skills. So, if Python is Perl for Germans, I’m, proud to quote JFK in saying “Ich bin ein Berliner” ;-) . Let’s see more Python at @Schuberg Philis in 2011 and beyond!

Categories: Open Source, Python, Scripting, Training Tags:

Damian Conway’s Quantum::Superpositions talk

October 23rd, 2010 No comments

All things considered, Damians Conway’s talk is Yet Another Perl6 Promotion (YAPP), but a damn fun one.  Highlighting some very funky new features that Perl 6 makes happen, in constant time. Theoretically.

Conway is one of the best speakers I’ve seen so far. His talks have speed, passion, a big dose of absurd humor and loads of geek references. If you have the chance to attend one of his talks: go see him, you won’t be disappointed, promise.

The talks starts with a lighthearted refresh of the history of quantum mechanics, unexpected revelations about Bohrs activities in modeling and winter sports and so on.
When the audience is under his spell Conway dives a bit deeper and shows many examples of Perl 6′s more natural syntax, and possible uses of superpositions. Showing how superpositions -called Junctions in Perl 6, are not just reserved for mad scientists. Junctions might be damn useful for programmers; replacing contrived nested for loops with elegant code generating prime’s, testing list membership, doing string comparison, all the while letting Perl take care of parallelization automagically, in constant time. Theoretically.

A very simple example showing the power of superpositions, in Perl 5, taken from the description page of Quantum::Superpositions.pm:

$ideal = any( all("tall", "rich", "handsome"),
all("rich", "old"),
all("smart","Australian","rich")
);

Operations involving such a composite superposition operate recursively and in parallel on each its states individually and then recompose the result. For example:

while (@features = get_description) {
if (any(@features) eq $ideal) {
print "True love";
}
}

The any(@features) eq $ideal equality is true if the input characteristics collectively match any of the three superimposed conjunctive superpositions. That is, if the characteristics collectively equate to each of “tall” and “rich” and “handsome”, or to both “rich” and “old”, or to all three of “smart” and “Australian” and “rich”.

Find a good description of the concepts here, and most of the examples used in his talk on here but you’ll miss the funky Perl 6 rewrites of them. Junctions are documented in the Perl 6 documentation here.

Start using Superpositions/Junctions in Perl 5 by installing the Quantum::Superpositions module from CPAN. The module is currently maintained by Steven Lembark, and will only add the “any”, “all” and “eigenstate” operators. For a more up to date implementation with more junction operators and autothreading fetch Perl 6 by installing Raduko.

Can’t wait until Conway returns for part II: Time::Space::Continuum!

Less is more

June 30th, 2009 No comments

Every once in a while, I resort to one of the many “what’s my IP” type websites to lookup which external IP address I’m currently using. These sites have their uses for both professional, as well as personal purposes. Many of these sites provide a lot more information than I’m really after. In the end, I only want to see my current external IP address.

All the well intended, but known, technical and geo-location info presented by the numerous “what is my IP” sites tends to draw away attention from what you’re after and it doesn’t really play well with tools like ‘curl’ or ‘wget’.

There used to be a simple site I used, which just returned just your IP address located at http://www.whatismyip.org/, but this one also grew a lot of fat. Yesterday, I once again found myself looking for an external IP address, on a server with ‘curl’ and ‘wget’, and decided it was time I rolled what I was looking for myself. This turned into an extremely simple mod_python based scriptlet, which provides a no frills “What’s My IP” service, returning nothing more than a “text/plain” response with your current IP address.

This service is running on my recently upgraded employee rack server at Schuberg Philis at  http://ip.yppy.eu/. For me it provided useful and I hope other people also find this ‘less is more’ service of use. And yes, I will keep it clutter free.

Needs an OO Database but you have “only” Bash?

June 26th, 2009 3 comments

Have a look at this script from Stephane Chazelas appeared in the Appendix A of a very old version of the “Advanced Bash-Scripting Guide”.

#!/bin/bash
# obj-oriented.sh: Object-oriented programming in a shell script.
# Script by Stephane Chazelas.

person.new()        # Looks almost like a class declaration in C++.
{
  local obj_name=$1 name=$2 firstname=$3 birthdate=$4

  eval "$obj_name.set_name() {
          eval \"$obj_name.get_name() {
                   echo \$1
                 }\"
        }"

  eval "$obj_name.set_firstname() {
          eval \"$obj_name.get_firstname() {
                   echo \$1
                 }\"
        }"

  eval "$obj_name.set_birthdate() {
          eval \"$obj_name.get_birthdate() {
            echo \$1
          }\"
          eval \"$obj_name.show_birthdate() {
            echo \$(date -d \"1/1/1970 0:0:\$1 GMT\")
          }\"
          eval \"$obj_name.get_age() {
            echo \$(( (\$(date +%s) - \$1) / 3600 / 24 / 365 ))
          }\"
        }"

  $obj_name.set_name $name
  $obj_name.set_firstname $firstname
  $obj_name.set_birthdate $birthdate
}

echo

person.new self Bozeman Bozo 101272413
# Create an instance of "person.new" (actually passing args to the function).

self.get_firstname       #   Bozo
self.get_name            #   Bozeman
self.get_age             #   28
self.get_birthdate       #   101272413
self.show_birthdate      #   Sat Mar 17 20:13:33 MST 1973

echo

# typeset -f
# to see the created functions (careful, it scrolls off the page).

exit 0
Categories: Scripting, Unix Tags: , , ,