May 2008


Salesforce is incredible

David Carney, 29 May 2008

I’ve recently been learning all about Salesforce (www.salesforce.com) for a pending contract. Having not developed (or even used) a CRM-style system for quite some time, I was initially daunted when I first created a developer account and started tinkering. I had nightmares about leafing through arcane technical notes, hacking work-arounds, digging up old reference manuals, and all other sorts of things I’ve heard mentioned when people discuss systems like Oracle.

In short, I’m very, very impressed with Salesforce because:

  • It’s a software-as-a-service (SaaS), which means that they host all of the accounts, manage the hardware, maintain the databases, and so on;
  • It’s incredibly simple to create an account and start experimenting with the packages and “apps” they’ve installed by default;
  • They’ve built an entire community of developers around their product by providing a comprehensive array of APIs and, more importantly, something called the “AppExchange” on which anyone can post/share/sell/license applications and plug-ins they’ve created, post questions, and leave feedback;
  • I was dumbfounded by how easy it is to find documentation and examples;
  • Most importantly, it makes designing a CRM system *easy*. The hardest part is figuring out how your data should be modelled (which you have to do for any system using a database anyway). Once that’s done, everything else is dead-simple.

Of course, I still have a lot to learn. It’s just so refreshing to work with something that’s well designed and, for lack of a better word, intuitive.

Random Technical Facts

Peter McCurdy, 16 May 2008

I just want to mention a few random technical things that have come up recently and are worth sharing:

  • If you find yourself commonly running ps ax | grep myapp | grep -v grep, you should try ps ax | grep [m]yapp. Putting square brackets around any single character makes a regular expression that still only matches the string “myapp”, but doesn’t match itself. In particular, this is nice if the command line of the program you’re searching for contains the string “grep”, but in general it’s shorter and more correct.
  • In command mode in vim, Ctrl-Y and Ctrl-E scroll the view up and down, respectively, without changing the cursor position, which is often nice. In insert mode, they insert the character that’s immediately above or below the cursor – this turns out to be surprisingly useful when you’re typing in

    #ifndef MY_LONG_HEADER_FILE_H
    #define MY_LONG_HEADER_FILE_H

    in new C/C++ header files – since #ifndef is the same number of characters as #define, you can just Ctrl-Y your way out of having to retype the define value. I often find it easier than copy-and-pasting the first line.

Does anyone else have any other similar little tips that make life a bit easier?

A Robust Interface for C Library Encoding Functions

Peter Zion, 14 May 2008

A common task for library routines is to encode one buffer into another, transforming the data in some way in the process, where the size of the required destination buffer depends on the contents of the source buffer. Simple examples of routines which do this include:

  • Functions that encode and decode between different character sets or code pages (eg. ISO-8859-1 to UTF-8 conversion)
  • Functions that escape and unescape binary data for text representation
  • printf-type routines: the data is variable-length because, for instance, string arguments may be of variable length
  • In C, even the strcpy routine falls into this category, since the length of the source string is determined by the contents of the source buffer

Typical C library routines, including many in the standard C library, deal with this situation by passing a buffer size to the encoding function, which then never writes more than that many elements to the buffer; the problem with this approach is that it doesn’t give any information about what size of buffer would have sufficed to encode all the data. Most code I have seen simply doesn’t deal with cases larger than those that fit in a fixed, arbitrary size output buffer, which often results in a bug that only appears for large or edge cases.

Higher level libraries typically return some sort of dynamically-sized buffer to which it has appended the data, such as a high-level string class, but there are potentially problems here too: there is usually a hidden cost, such as many memory reallocations, that goes along with appending large encodings to a dynamic buffer. There is also usually an overhead (however small it may be) to using dynamic buffers in cases where raw, stack-allocated buffer would have sufficed.

One surprisingly simple and elegant but rarely seen way to handle such functions in C is to return the size of the buffer that would be required to hold the entire result instead of the number of elements written. To understand the benefits of this, imagine that such a function had the prototype

size_t Encode( char *buf, size_t buf_len, const char *data );

When you then use such an encoding function in your code, you can both avoid memory allocation in small cases and at the same time allow arbitrarily long encodings as a fallback, as this example illustrates:

char small_buf[256];
char *buf = small_buf;
size_t required_len = Encode( buf, 256, data )
if ( required_len > 256 ) // (use unlikely() here when possible)
  Encode( buf = malloc( required_len ), required_len, data );
// Do something with buf... when done, make sure to clean up:
if ( buf != small_buf )
    free( buf );

The key point to take away here is that we don’t actually allocate any memory unless we are encoding a particularly long string, which is often an exceptional case, and yet the size of the encoding output is limited only by the largest contiguous virtual memory block available. Note also that min( buf_len, required_len ) is precisely the number of bytes written to the buffer, whether or not all the data was encoded; if all the data was encoded, this is precisely the encoding length.

When using this style, it is helpful to allow the passed buffer pointer to be NULL, in which case the function simply returns the size of the buffer necessary to hold the results even though no such results were returned.

As an example of a routine using this style, here is a function to encode a string by backslashing double quotes and backslashes:

size_t c_quote_str( char *dst, size_t dst_len, const char *str )
{
  size_t required_len = 0;
  for (;;)
  {
    if ( *str == '"' || *str == '\\' )
    {
      if ( dst != NULL && dst_len > 0 )
      {
        *dst++ = '\\';
        --dst_len;
      }
      ++required_len;
    }
    if ( dst != NULL && dst_len > 0 )
    {
      *dst++ = *str;
      --dst_len;
    }
    ++required_len;
    if ( *str++ == '\0' )
      break;
  }
  return required_len;
}

Getting nice fonts in gitk

Peter McCurdy, 12 May 2008

A comparison of gitk's fonts using Tk 8.4 and 8.5
If you use git (and you should), you may have noticed that gitk’s fonts generally look bad. Some of them aren’t too terrible, but a few, such as the menu bar font on my machine, are really bad. Stupendously awful. Like they’ve been run through a blender. You get the idea. None of them are all that great, anyway. Newer versions of gitk at least let you pick larger fonts, to save you from the default squint-o-vision settings, but that just makes them large and ugly instead of small and ugly.

The sad thing is, it’s not even gitk’s fault. gitk is written in Tcl/Tk, which, despite being somewhat underrated as a language, has some very questionable font handling in the toolkit. However, there is hope: the recently-released Tk 8.5 finally brings some antialiased fonts to the table. To my eyes, the antialiasing is actually somewhat overdone, but that’s nitpicking; the overall improvement is staggering. So just get yourself a copy of Tk 8.5, and you’re off to the races.

Ah. Unless you’re using Ubuntu. While the new Ubuntu 8.04 has Tk 8.5 available for installation, they’ve restricted gitk to explicitly ask for Tk 8.4. So, to get yourself nice fonts in gitk on Ubuntu 8.04:

  • Install Tk 8.5: sudo aptitude install tk8.5
  • Open /usr/bin/gitk in a text editor.
  • On the third line, change “wish8.4″ to “wish8.5″

Presto, nicer-looking fonts. You can see the difference in the image up top, where I superimposed the old and new toolkit versions. Needless to say, Tk 8.5 is on the left.

Update, 2009-11-21: According to the (very helpful – thanks guys!) comments, in more recent versions of Ubuntu, and presumably Debian as well, the solution is a bit easier. Once you install tk8.5, just run sudo update-alternatives –config wish and pick /usr/bin/wish8.5 from the list.

On Becoming a Cooperative

David Carney, 10 May 2008

So, I’ve been tasked with getting our paperwork in order while mcote is gallivanting around Europe and it’s not at all clear if we must have (at least) five signatures on our “Attestation”, which the CDR will use in our application to the government.

Regarding a constitution, the Cooperatives Act clearly states:

7. At least five founders are required to apply for the constitution of a cooperative.

But, shortly thereafter is says we must include the following with our application:

12.1) an application for the constitution of the cooperative signed by two founders;

I’m hoping this means that only two of us have to sign it. As-is, only four of us live in Quebec; the remaining three are in Ontario and Nova Scotia. Regardless, I’ve emailed Chandy Ly (our contact at the CDR) and left a message on their answering service. Things should be resolved by Monday afternoon.