Django custom model field for an unsigned BIGINT data type

Web 2.0 social media platforms tend to think “big”. They hence often use big integers (8 bytes / 64 bits long instead of just 4 bytes / 32 bits like a normal integer) for user IDs (or sometimes message IDs) to be prepared for even the most extreme potential future growth of their user base. Usually, these big integers are unsigned, allowing for up to 18’446’744’073’709’551’615 UIDs to be stored (which is probably enough to register the inhabitants of quite a few other blue planets too ;).

Facebook, with currently more than 300 million active users, also uses  a 64 bit unsigned integer for storing user IDs and expects Facebook applications to be able to handle this. Of course, 300 M user IDs would still easily fit into a 32 bit unsigned integer, but Facebook already goes beyond the 32 bit limit by issuing 15 digit UIDs like 100’000’xxx’xxx’xxx to registered test users (which allows Facebook to better distinguish between test accounts and real accounts).

Now if you happen to use Django to build your Facebook application, this fact needs special attention as Django doesn’t support 64 bit integer field types for its ORM models by default. As a Django developer, you could thus resort to using a CharField for storing Facebook UIDs (which would be odd) or, better, define a custom model field you can use in your models instead of IntegerField. Fortunately, Django offers an elegant way to define custom model fields. You can write your custom PositiveBigIntegerField by simply subclassing (extending, inheriting from) models.PositiveIntegerField:

So, in your models.py add the following code:

from django.db import models
from django.db.models.fields import PositiveIntegerField

class PositiveBigIntegerField(PositiveIntegerField):
    """Represents MySQL's unsigned BIGINT data type (works with MySQL only!)"""
    empty_strings_allowed = False

    def get_internal_type(self):
        return "PositiveBigIntegerField"

    def db_type(self):
        # This is how MySQL defines 64 bit unsigned integer data types
        return "bigint UNSIGNED"

class Mytest(models.Model):
    """Just a test model"""

    huge_id = PositiveBigIntegerField()

    def __unicode__(self):
        return u'id: %s, huge_id: %s' % (self.id, self.huge_id)

(NB: The “Mytest” class is just for testing the PositiveIntegerField definition, it’s not part of the PositiveIntegerField definition.)

Note that this solution only works for MySQL as a database backend (as MySQL supports the “bigint UNSIGNED” data type for columns which isn’t defined in the SQL standard).

For testing, define a “Mytest” model as shown above and execute “python manager.py syncdb” to create a new myapp_mytest table with an unsigned bigint(20) column named huge_id. Register this new model “Mytest” in admin.py, restart runserver and you’ll be able to enter 64 bit integer values through Django’s admin application.

The only minor “issue” is that Django admin’s CSS class (.vIntegerField) used for HTML form input fields representing integer values defines the width as “5em” which is a bit too narrow to display the entire 64 bit integer. This can be adjusted however (e.g. by writing your own ModelForm and telling ModelAdmin to use that, see the Django admin documentation and the Widget.attrs documentation).

P.S. Note that for Django to be able to access and use a “bigint UNSIGNED” data type, you don’t necessarily need to define a PositiveBigIntegerField and adjust your models. Instead, you could simply adjust the column type in MySQL accordingly as a quick-fix. If you use syncdb (like most Django devs) and want it to create your tables and columns correctly however, defining a custom model type as described is the way to go and strongly recommended for consistency and QA.

Thunderbird Add-on: S/MIME Security for Multiple Identities

I’ve just found and installed the following add-on for Mozilla Thunderbird:

S/MIME Security for Multiple Identities

It allows you to use a different S/MIME certificate for each of the different identities (i.e. “e-mail address aliases” or “profile aliases”) you defined in your Thunderbird profile.

It’s currently still marked as an experimental add-on and I’ve noticed a minor glitch in v0.3.0 when using it (see my add-on review), but this might also be related to the fact that I also use the Virtual Identity add-on (another nice add-on which allows you to use an arbitrary sender address for sending messages).

The “S/MIME Security for Multiple Identities” add-on is very convenient if you have multiple e-mail accounts and want to use S/MIME message signing and/or encryption with all of them.

Bonus hint: You can get your own, personal S/MIME certificates for free at Thawte (for e-Mail only) or StartCom/StartSSL (also offers free class 1 SSL/TLS certificates for FTP servers, web servers etc. -> the latter don’t “work” with Internet Explorer, however).

Simultaneously using multiple accounts with Skype 4.0

As an addendum to my earlier post, I’ve just noticed that a) Skype 4.0 Beta 2 runs pretty stable on Windows Vista 64 and b) has built-in support for managing multiple Skype accounts! With the help of this feature, you could for example set up a private account and a business account and use both of them at the same time, using the same Windows user account. The setup is straightforward:

1) Install Skype 4.0 Beta 2

2) Create a shortcut to Skype.exe and place it on the quick launch bar. Rename the shortcut to “Skype Private Account”, for example. Start Skype using this shortcut and setup your first account (in this case, your private account).

3) Create another shortcut to Skype.exe (add it to the quick launch bar, too) and name it “Skype Business Account”. Open the “Properties” dialog of this shortcut by right-clicking on it. In the “Target” text field of the properties dialog box, append ” /secondary” (without double quotes) to the Skype.exe path that is already there. For example, in my case, the “Target” text field contains:

“C:\Program Files (x86)\Skype\Phone\Skype.exe” /secondary

Rename this shortcut to “Skype Business Account” (right-click->rename). Having done this, start Skype using this shortcut. Skype will then prompt you to enter the credentials of another Skype account of yours (in this example, of your business account).

You can also choose different icons for the two shortcuts. Further, I’d assume the /secondary feature isn’t limited to managing two Skype accounts, though I haven’t tested it with more than two accounts. The main advantage of this “/secondary” feature is that you don’t need to have a separate Windows user account for each of your Skype accounts. Note however that, even with this solution, a new instance of Skype will be created for each of your Skype accounts – every instance consuming about 40 MB of RAM.

I think that’s a very useful feature and I like it a lot.

Google Chrome from a business and “techie” view

If Google will really deliver what it promises with its new Chrome browser plans (Google blog) (personally, I have no doubts about this), the line between web applications and standalone applications will further blur and hereby enable a better, seamless user experience and probably a whole new class of powerful applications.

Some thoughts:

  • From a technical point of view, Google’s Chrome will be the WebOS others have been dreaming about for a long time already. It basically offers memory management, process management, markup renderers, a GUI and a VM with a JIT compiler (V8).
  • It will finally unify the ideas behind the WebOS, “The network is the computer”, cloud computing, SaaSRIA and virtualization.
  • Actually, it’s astonishing it took so long for someone to come up with something like this. The concepts as such are not new at all, but the combination of all these different concepts is what makes the thing cool. It’s typical for a good idea that, once you’ve heard of it, you almost can’t imagine living without it anymore, as it seems all so natural.
  • Detachable tabs on top: Not a new idea either. For example, I remember that the Fluxbox window manager actually offered the same feature back in 2001/2002 (or even earlier) already. I remember it as I used it myself too (and I liked it a lot, despite of its “suboptimal” scalability), as illustrated in these animations:
    Fluxbox Window Grouping Feature (2002) 1/2 (small animated GIF screenshot)
    Fluxbox Window Grouping Feature (2002) 2/2 (large animated GIF screenshot)  

    I guess there were other window managers and GUIs that had the same features even before fluxbox had them.

  • With this move, Google will be gradually taking control and power away from traditional Desktop OS manufacturers such as Microsoft and Apple. Being open source, Chrome and its components like V8 will be the “Linux of the web” and thus a big threat particularly to Microsoft that still generates most of its revenue with Windows and standalone applications like Office.
  • The ongoing process, that (desktop) operating systems are becoming commodities more and more, will further be accelerated. Will there be an “unsacred” alliance between Apple and Microsoft to fight these tendencies or will they shift their businesses further into the “web” application (SaaS), content (music, videos, TV, e-books, multimedia etc.) and lifestyle (design, hardware, ethics) spaces?
  • Of course that’s in the best interest of Google (as their business is data/content and webapps/SaaS). I wouldn’t call this move an evil move, but it’s definitely not a friendly move in the eyes of the competition.
  • From a “techie” point of view, this move will enable many interesting applications in the future. As the framework will be open source, the dev community will potentially be as vital and dynamic as in other high-profile OSS projects (like Mozilla, Linux)
  • What about the Mozilla, Safari, IE, Opera camps? They will have to adapt themselves to the concept and try to top it. IE (and perhaps also Safari) might try to take the “embrace and extend” route.
  • With the birth of the WebOS, there will probably be a need of an open, standardized webapp GUI toolkit and webapp GUI guidelines soon (and there’s a big potential for conflicts here). Who will provide these? What will be the roles of the current big players? Also, standardized, open specs for user authentication and user data exchange will be required – here, there’s already some progress with OpenID, OAuth etc.
  • I like that Google communicates its plans using an easy-to-follow cartoon and that they give credit to individual internal and external contributors and players (though I assume there were much more people involved in the process than those mentioned)
  • The thing that disappoints me a bit is that when talking about V8, they only talk about targeting JavaScript. I’d prefer a more generic approach providing a VM and JIT for various languages (similarly to a CLI VM – why not re-use/extend Mono, for example?). Maybe that’s what V8 actually provides and they just don’t emphasize it at this point in order to not confuse or upset end-users, devs, big players etc..
  • Taking a look at the big picture, it seems that there’s a very pragmatic driver behind this whole development: It’s the laziness of us end-users (just as a fact, not meant in a negative sense – being “lazy” is usually quite rational). Or in other words: The information takes the line of the least resistance. And so far, that line for the “Network OS” happens to be the web, i.e. basically HTTP, despite of its known shortcomings.

[UPDATE 20080902: Corrected a typo. And here’s a statement regarding the Google Chrome news by John Lilly, CEO of Mozilla Corp.]

Multiple Skype accounts on one computer

It’s a bit of a hack as with this solution, Skype’s memory usage will grow linearly with every additional instance of the Skype client you run (about 40 MB are required per instance), but at least it seems to work fine on Windows XP:

http://www.tradebit.com/channels/software/110543/multiple-skype-accounts-on-one-computer/

Note that the double quotes should be simple double quotes, not typographical ones. So for 2.) the link’s destination should be sth like

%windir%\system32\RUNAS.exe /profile "/user:skype2" /savecred "C:\Program Files\Skype\Phone\Skype.exe"

(Of course you need to adjust the paths and user to your environment and settings)

Alternatively, particularly if you use Windows Vista, you could try this free Skype launcher (I haven’t tested it):

http://forum.skype.com/index.php?showtopic=88055

Since this launcher doesn’t seem to use dedicated Windows user accounts on your box, you’ll have to disable Skype’s auto-login feature in order to use different Skype profiles.

Why did the line spacing change in Word 2007?

Did you ever wonder why Microsoft changed the line spacing in Word 2007? Well, here’s the answer:

Why did the line spacing change in Word?

And the “fix” is here:

Make my document look like a Word 2003 document

Some general information about how to adjust the line spacing and paragraph settings in Word 2007:

Adjust the spaces between lines or paragraphs

Personally, I like the new GUI approach in Office 2007 and its improved usability, but the new styles (with this very unusual line spacing) kind of overshoot the mark.

Firefox 3 – suggestions for GUI design improvements

Some suggestions for improving the GUI of FF 3:

  • Why does the forward button have a very different shape than the back button (round vs. rectangular)? On IE 7, both have the same shape (round) which is more consistent and more user-friendly (as they’re both navigation icons, just for opposite directions). BTW: Yes, I know the official answer, but the different size is still no excuse for different shapes.
  • Why does FF 3 try to squeeze as much information as possible into the URL text field? Instead of combining the security certificate information with the favicon display (a fact that likely confuses users, particularly Joe Average), one should rather reserve a dedicated place just for displaying the security information (like IE 7 does).
    The star (bookmark??) icon within the text field is also disturbing as it doesn’t behave the way a sane user would expect it to. Instead, clicking on it creates a bookmark (without asking for confirmation), clicking on it again doesn’t just silently remove it again (without asking for confirmation), but rather displays a dialog box with bookmark properties (and another button to remove the bookmark, eventually). Further, the bookmark icon behaves quite different than the analogous magnifier/search icon in the search box.
  • Why isn’t it visually more obvious to the user whether (or not) a connection is properly encrypted and the server properly authenticated through a certificate? Why not use a light-green (or light-yellow) background color (again) for the URL text field of properly secured connections? Instead, all the user is left with now is an almost unnoticeable background color change of the favicon display area and a “secured lock” icon in the status bar. (Note: IE 7 does it better, but only a bit.)
  • Why did they choose blue as the color to indicate a secured connection (the same goes for IE 7)? I’d rather choose green (or maybe yellow, but definitely not blue).
  • Why does the drop-down icon in the URL text field look different than the drop-down icon in the search field (mouse-over tinted vs. permanently tinted)? Only God and the GUI designer know. But it surely confuses users as it isn’t consistent. (BTW, IE 7 is also inconsistent in this regard.)
  • In my view, placing the reload and abort icons after the URL text field (as in IE 7) instead of in front of the URL text field would be more natural.

Jingproject, screencast.com and Logitech G9 Laser Mouse SetPoint 5.0

I’ve just installed the free (as in ‘free beer’) Jingproject client by that allows to capture screenshots or screen videos and store or upload and share them (e.g. on screencast.com). It’s amazing, how easy and convenient it is to use – good job! There are clients for both Windows and Mac OS X (which will likely be important for me very soon as I intend to buy a new MacBook Pro with LED backlit display and a Penryn Core 2 Duo processor). The only thing missing is a Linux client (but we’re used to that, aren’t we? ;). Jingproject is provided by TechSmith, the creators of the well-known (and also great) SnagIt screen capture application.

Here’s an example of a screencast I just recorded (no sound, though):

Logitech G9 Laser Mouse SetPoint 5.0 German

It shows the great variety of configuration options you have for customizing your Logitech G9 Laser Mouse using SetPoint 5.0. The Logitech G9 Laser Mouse is Logitech’s latest “gamer” mouse and the best and most accurate mouse I ever used. I bought it though I’m not much of a “gamer” actually, but the form factor, features and its high quality convinced me. It’s quite a small mouse compared to other mice, but that’s intentional as you move it with your fingers rather than with your wrist or arm. This makes it a very user friendly (and particularly gamer friendly) pointing device as you’re much quicker in pointing and clicking while using less energy. The small form factor however might be a problem for you if you have really big hands (check it out in the next hardware store before you buy!).

Further, it’s a mouse with a cord, so you don’t need to worry about batteries, lag or interferences. So in short, I highly recommend the Logitech G9 Laser Mouse. For me, the only minuses are its rather high price and the fact that there is no SetPoint for Mac OS X (let’s hope Logitech will port it soon).

9 out of 10 points from me.