Adding UI to make up for your UI

Sometimes applications don’t respond because, well, they’re busy. But only the most special of apps treat this not as a bug, but something to put up a “nothing to see here, move along” notification:

Microsoft Visual Studio is Busy

I mean, the sad part is I actually understand why they likely implemented this instead. At this point in Visual Studio’s lifecycle, it’s easier just to poll to check if the UI is unresponsive than to actually root out the cause of the unresponsiveness. It’s sad, actually. And the fun part is, in preparation for this blog article I didn’t even have to try very hard to get that little balloon to pop up. Took me about 30 seconds (and no I’m not going through the trouble of reporting it to Microsoft because it’s not entirely repeatable and I’m skeptical of what the results would be anyway). Go Visual Studio.

Another SSIS Wart

As I get more and more educated on SSIS, I’m becoming more appreciative of what it does (or in some cases, intends to do) overall but I’m also finding some of the weirdest things that are just a little “off”. Most are just the kind of things that make you go “huh, that’s strange”, but I found one yesterday that made me seriously stop and scratch my head because I was just completely lost as to why things would be done this way. In fact, if it weren’t for the Wrox SSIS book that I got, I probably wouldn’t have figured out the answer.

I’ll start this off with a quick question for you to ponder the answer to before I go into the details — What is a “property” on an object other than essentially just a variable defined only within the scope of that object? Rather than answer that question just yet, here’s the problem I was scratching my head over. In SSIS, they have some nifty pre-defined events which you can easily attach event handlers to. Thanks to Jamie Thomson’s blog post entitled “Custom Logging Using Event Handlers” I’ve been happily coding away logging routines using the OnPreExecute and OnPostExecute event handlers (among a few others). But, I soon ran into a problem that wasn’t addressed in the blog post, and that was that every event that fires propagates up the call chain, regardless of whether or not the event is handled[*]. That is to say, if I have an SSIS package that has (”contains”) a task which loads a file into a database, and I define an event handler for OnPreExecute that simply writes a row to an event log that says “Started: “, then once it gets to the file load task, the database will contain the following:

  1. Started: Main package
  2. Started: File load
  3. Started: Main package

Obviously that last row is a bit silly because the main package didn’t just start, it’s in the middle of executing all of its tasks. That’s because the PreExecute event propagated up from the file load task. Now, one might argue that propagating that particular event doesn’t make a lot of sense because you only ever PreExecute once for each task, and it certainly has nothing to do with when the child tasks do anything. But, for the sake of consistency I can forgive that. If that was the wart, then that’d just be a “huh, thats strange” kind of wart. After all, you certainly do want Error and Warning events to propagate up so you can just define event handlers for those in the parents.

So, at this point I figure there has to be some way to prevent the upward propagation of some events, even if I have to specify it per event handler. The first place I looked was in the properties for the event handler. The only thing that looked mildly promising was the LoggingMode property, but that was limited to “Use Parent Setting”, “Enabled”, or “Disabled” - nothing about “handle and stop propagating”. So, the next place I checked was the “expressions” for the event handler. Expressions in SSIS are basically ways of setting properties that are dynamic (ie, can change at/during runtime), and they’re very useful and generally contain most of the properties anyway, plus an occasional extra tidbit. Well, no extra helpful tidbits in this case, though I was positive that was where it would be.

What does any good programmer do when they’ve exhausted their available local resources? Google it, of course. Unfortunately no matter what search string I used (and my Google-fu is pretty good), I couldn’t find anything that would tell me how to do what I want. Plus, the only other SME on SSIS in the company that I’m aware of was unavailable to ask, and I’m about to outgrow using him as a reference anyway. Then I remembered the aforementioned book, and sure enough one of the first things in the index under events was “bubbling”. And in less than 2 minutes of reading, I had my solution.

Now for the solution and then a quick revisit to the question I kicked this story off with. The solution: there is a “system variable” defined at the error handler scope level entitled Propagate, which if you set it to False will not propagate the event to its parent(s). How the heck is a system variable defined only within the scope of a single object (and obviously only useful within that scope) a better choice than a property? Properties are displayed in a nice little grid that’s easily accessible. System variables are hidden behind several clicks in the interface. I’d wager that 95% or more of SSIS packages never have to muck about with them, and none of the dozen or more packages I’ve worked on have ever needed to do so (until now!), in spite of all the functionality I’ve included. Thankfully, I’m not the only one who had such an issue (I didn’t find that blog post until I started writing this one, and he doesn’t have the solution in his post, but Jamie Thomson posted a response which he found).

And to make matters worse I just realized that this means I’ll have to define that variable for all children within a package otherwise I’ll get a lot of “Started: Main package” messages, one for each sub-task (which is a lot, including checking for input, truncating tables, etc.). According to the blog post and response linked at the end of the last paragraph, there’s no way to tell an event handler to not listen to propagated events either. Sigh.

[*] - it also doesn’t help that Microsoft’s documentation has a very misleading/incorrect diagram showing event propagation stopping at the first handled event

The Nerd Handbook

So that we don’t get into too deep of a posting morass, here’s a good link that was posted on reddit (though I found it via the SomethingAwful forums):

http://www.randsinrepose.com/archives/2007/11/11/the_nerd_handbook.html

RFC: Gearing an Open Source talk to a Microsoft heavy crowd

When I was hired on at my new job, I was apparently referred to internally as “the open source guy”. Now, that’s a moniker I don’t really mind because I do espouse the open source/free software philosophy and I definitely see it as being useful both from a personal standpoint and as a professional developer. Well the new gig heavily encourages knowledge-sharing and building of “intellectual capital” via presentations and such, so I thought that open source as a community, development strategy, and philosophy might be a worthwhile thing to share. So, this is my request for comments on ideas for what to present. But rather than just asking that question, here’s sort of what I had in mind.

First I’d have to do some definition/demystifying up front: answering the who/what/why’s and all that, because this is a heavy Microsoft crowd, though not so much that they are fanboys or anything like that (well, some might be but they likely won’t attend) it’s just what they know and that’s what the clients run on. I know at least a few people, including some of the partners, are genuinely interested in open source not only as a business strategy but as a community. So I think the first few big talking points in this section would be:

  • What is open source? (I’d like to stick mostly with definitions here and not delve too much into history and/or the fractious issue of what constitues “free” or “open source” software)
  • What open source projects they might be aware of, even if they don’t know they are open source (Linux, Mozilla, Java (yes, Java), PHP, Subversion, etc.)
  • What open source projects affect them that they are likely unaware of (Apache, Python, MySQL, Mediawiki (wikipedia))
  • Why open source? (Why do developers give away code? Why use it?)

And that would be the bulk of the presentation. From there I can come up with a more directed approach talking about how my company can leverage the advantages of open source to help increase productivity/add value/etc. Really I just wanted to hear what people thought about the first part and whether or not I was missing anything or perhaps should take some stuff out. Though if anyone has any feedback for what open source could mean for a small IT consulting firm, then by all means, fire away :)

Understanding ‘global’ in Python

In one forum I read, many people do not seem to know how to use the global keyword in Python. The most common misconception is that the declaration global foo will make foo global. That is wrong. global tells Python to use the global definition of foo instead of creating a local definition. Let’s see with an example.


>>> foo = "foo"
>>> def func1():
...   foo = "bar"
...   print "Inside func1():", foo
...
>>> def func2():
...   global foo
...   foo = "baz"
...   print "Inside func2():", foo
...
>>> print foo
foo
>>> func1()
Inside func1(): bar
>>> print foo
foo
>>> func2()
Inside func2(): baz
>>> print foo
baz
>>>

In func1(), when I assigned the string bar to foo, Python created a new foo, local to func1() which shadowed the original foo. Which is why before and after the function call, the value of foo (the global one) was “foo”.

Inside func2(), I specifically told Python that I wanted to use the global value of foo, not create a new local one like I did in func1(). This is why the value of foo (the global one) is changed when we do print foo after the function call.

Feedback wanted for a C function

Attention fellow Grasshoppers, I need your input on a C function I wrote. As you may know, I’ve recently decided to give C a serious look. The first project I decided to write is a simple RPN calculator. Last night, I wrote a function to verify if a string is a valid number representation; I wrote a few test cases using assert() and it seems to work pretty well (speaking of testing, do you have any recommendations for testing frameworks/libraries for C?) I do find the code long however, and the last loop seems complicated. Here it is (let’s hope Wordpress doesn’t mess up the formatting):


int isnumber(char *s)
{
    size_t i;
    size_t len;
    int period = 0;

    /* Skip over white spaces. */
    while (isspace(*s))
        ++s;

    if (*s == '+' || *s == '-')
        s++;

    i = 0;
    len = strlen(s);

    if (len == 0)
        return 0;

    for (i = 0; i < len; ++i) {
        /* Only one period is allowed. */
        if (!period && s[i] == '.') {
            period++;
        }
        else if (period && s[i] == '.') {
            return 0;
        }
        /* Ignore everything after a space. */
        else if (isspace(s[i])) {
            return 1;
        }
        else if (!isdigit(s[i])) {
            return 0;
        }
    }

    return 1;
}

Let me know what you think and what could be improved. I’ll appreciate any input, whether it’s stylistic, functional, security-related, performance-related, etc.

Not a WTF, but certainly a wart

As you may know, I’m not that much of a fan of Microsoft technology, but understand that it’s somewhat unavoidable and allowing for the use of MS products greatly opens the prospects of employment/work. So, at my new gig I’m aware that a healthy chunk of time spent doing development will be using Microsoft tools and all the quirks that go along with them. Sometimes I’m pleasantly surprised, sometimes I’m reminded of why I dislike Microsoft products in general. Lately it’s been more of the latter.

On the current client I’m designing stuff for, we’re using MS SQL Server 2005’s SSIS toolchain, which is a great idea with mediocre execution. For those who are unfamiliar with SSIS, it’s basically the evolution of their DTS package that came with SQL Server 2000, which is designed to simplify the ETL process of getting data from a source (or various sources) into the destination database after all sorts of cleansing and transformation. The DTS package that shipped with SQL Server 2000 was apparently pretty warty, a trait that is common amongst first-gen Microsoft products, and so SSIS is apparently notably cleaner and nicer. But, as most of us are aware, that doesn’t mean it’s wart-free, and I’ve found a nasty wart or two.
Continue reading ‘Not a WTF, but certainly a wart’ »

Multiple RTP pools for Asterisk

In Asterisk’s current state, it supports one RTP pool from which it selects a random pair of ports (RTP and RTCP) for each leg of a call. As part of a project at work, we need Asterisk to support multiple pools of RTP ports — specifically one pool for local calls and one pool for calls which have a leg on an external network. The reasoning behind this being that local calls only funnel their RTP traffic through Asterisk for a short amount of time and then the phones re-INVITE each other, cutting Asterisk out of the picture. Since there’s so little involvement with Asterisk for local calls, we’re ok with having a fairly large pool of RTP ports available (and therefore calls that can be initiated) without worrying about stressing our Asterisk system.

This isn’t the case when we have a call involving a remote leg, where all RTP traffic is running through the Asterisk system. Since we want to have a large RTP pool for local calls and RTP pairs are chosen randomly, we’re unable to simply use a firewall to limit how many connections can be made to the system. Doing so would risk having the external phone instructed to use a firewalled port and therefore lose half of the audio stream.

To address this, I submitted a patch for Asterisk to have a concept of two RTP pools. I left the current pool and its configuration alone and added the ability to optionally specify a “remote” pool. The patch comes in two parts. The first enables configuring the remote RTP pool (specified by the remotertpstart and remotertpend config vars in rtp.conf) as well as providing new functions to create an ast_rtp struct using the remote pool. By default, everything acts as before — the remote pool is the same as the local pool. The second part changes chan_sip to make use of the new remote RTP pool if it detects a remote leg and localnet/externip are set in sip.conf.

Since I think this functionality could be useful outside of my work environment and I’m fairly new to fiddling with Asterisk’s internals, I’d appreciate any feedback on the patch itself and/or actual usage of the feature. As implied above, my patches will only affect SIP calls. Support for other channels would have to be added (if it makes sense).

Back into the Django fray for a bit

To sort of go along with the fantasy football related programming post from earlier, I also like to do a set of “power rankings” for the NFL using a fairly simple but data-heavy formula that I derived via a bit of trial and error and really just some thought exercises. For the past season or so I just maintained it using a simple spreadsheet (at first Excel, then Gnumeric once I converted my laptop to Linux after getting the new job), but even when I was doing it I noticed data inconsistency which almost definitely resulted from data entry errors on my part. For example, part of the formula involves a teams “points for” (points they score against other teams) and “points against” (points other teams score against them). Well, when you sum up the “points for” for all the teams, and when you sum up the “points against” for all of the teams, you should get the same number. But sometimes I wouldn’t. Those errors weren’t quite as nefarious to track down as other things like in my strength of schedule calculations the total W-L record of one component should be the mirror opposite of another, but it would be missing some wins somewhere.
Continue reading ‘Back into the Django fray for a bit’ »

Blog reviews

I think in an attempt to have good, quality content, before we publish a post, we should make somebody else proof read it for spelling mistaeks, content accuracy, etc. What do you think?