(Not) trapping Ctrl F4 and Ctrl W in Google Chrome

I couldn’t do it. Ctrl, F4 and W individually get to the onkeydown handler just fine. With ctrl+F4 and ctrl+W, the ctrl key is caught, but Google Chrome eats up the F4 and W and closes the tab.

It makes sense, I think. I wouldn’t want an “antivirus” or spam website preventing me from dismissing the tab with prejudice!

Posted in Software Development | Leave a comment

Executive summary of the COM threading models

Single Threaded Apartment

  • A thread is initialized to belong to a COM apartment with CoInitialize(NULL) or CoInitializeEx(NULL, COINIT_APARTMENTTHREADED).
  • An STA component instantiated in an STA thread resides in it.
  • All calls to the component from components outside it’s STA are marshaled and posted to the thread as a message.Calls to the components from components within the STA are not marshaled.
  • All STA components created in an MTA are placed into the host STA. There is only one host STA per application.

Multi Threaded Apartment (aka Free Threaded Apartment)

  • A thread is initialized to belong to a COM apartment with CoInitializeEx(NULL, COINIT_MULTITHREADED).
  • There is only one multithreaded apartment in an application. Any thread initialized as multi threaded belongs to this apartment.
  • Calls to MTA components from other MTA components in the same app occur directly without marshaling. Calls from STA components are marshaled.

Both

These components can run in MTAs and STAs. If instantiated in an MTA, the object will be an MTA component. Likewise if instantiated in an STA, it will be considered an STA component.

More reading

  • http://blogs.msdn.com/b/larryosterman/archive/2004/04/28/122240.aspx – A good read for getting a handle on the basics.
  • http://msdn.microsoft.com/en-us/library/aa480451.aspx – Explains the concepts underlying each of the COM threading models
  • http://support.microsoft.com/kb/291670 – Describes the host STA
  • http://www.codeproject.com/kb/com/CCOMThread.aspx – Detailed explanation of the Single Threaded Apartment model
  • http://msdn.microsoft.com/en-us/library/ms809971.aspx – Explains Single and Multi Threaded Apartment models, going into some depth
Posted in Software Development | Tagged | Leave a comment

The problem with NetBIOS

Mention NetBIOS in a room full of system admins, and a cold draft seems to spread through the room. It’s as they could sense Darth Vader nearby.

I finally decided to get to the bottom of this discomfort. It turns out that NetBIOS’ null sessions have much to answer for. What follows is a compendium of links that explains the problem.

How to secure a box with NetBIOS enabled: Restrict anonymous enumeration

A quick summary

The NetBIOS component’s security holes have been patched by Microsoft. But the default installation of NetBIOS leaves much to be secured. By default, it’s possible to connect anonymously to the IPC$ share on a machine. Once connected, the NetBIOS Session Service can be queried for a complete list of users. The harddrives are shared by default for administrative purposes as c$ and d$. These shares are hidden, but can be accessed by someone with valid credentials. Armed with a knowledge of all usernames on the machine, it’s possible to guess the password of some user with admin rights by a brute force attack on one of the harddrive shares, and after authenticating successfully proceed to wreak havoc.

Some of the links above describe steps to secure NetBIOS. But most recommend that if it is not needed, it’s best to disable it.

Posted in Software Development | Tagged | Leave a comment

Samsung Galaxy S: Notes

I purchased this phone just a few days ago, so what follows are some young impressions that may change or mature with time. I have not taken the trouble to separate my comments on the android platform from those on the design of the phone.

What works:

  • Android has a drawer that is pulled down from the top that displays notifications of various events, including messages, mail and downloads. This drawer can be pulled down from within any app. It allows you to toggle wifi, bluetooth and a couple of other features. Notifications will typically alert you with a sound, but will not disturb you until you pull down the drawer.
  • Many articles about android apps (such as this) publish a bar code that refers to the app in the marketplace or a page on the web. I often find out about interesting android apps on my laptop. I then use the Barcode Scanner app (free on the Android Marketplace) to scan these bar codes on my phone and quickly download the app I want.
  • Put your favourite scripting languages on your android phone with the Scripting Layer for Android!
  • USB debugging mode: This allows you to treat your Android phone like a USB drive, which in turn makes it easy to save and retrieve scripts for the Scripting Layer for Android app that I have mentioned above. Maybe the same effect can be achieved through an android ftp server. I haven’t looked up an ftp server yet for my phone.
  • Platform: I have read parts of http://developer.android.com/guide/topics/fundamentals.html. What’s not to like about a component and message driven platform!
  • Swype: A new way to type. The best way to understand is to see it.
  • The screen remains eminently readable in daylight. I’m not sure yet about direct sunlight. I’ll try that soon and update this article.

What needs improvement:

  • GPS has not worked well for me so far. I get my location with AGPS. Various articles report that Samsung is aware of this and will provide an update as soon as possible.
  • Android 2.1 does not support proxies, and this is the version that my Galaxy S shipped with. There are hacks around that provide some limited support for proxies on Froyo. My phone will get Froyo next month, so I have not been able to use any of them.
  • Android hasn’t got as many apps as the app store. I’m sure this will change with time.

Not so good, but not too bad:

  • The Galaxy S has no trackball. There is a way to access virtual arrow keys in place of the trackball when entering text. Still, I haven’t had much trouble without the trackball over the last few days.
  • There’s no button on the side for silent mode. But it’s available within easy reach from the handy drawer that I mentioned above.

Update on August 24, 2010: What’s changed since I posted this

  • GPS started working with the last update (no Froyo yet) to the Galaxy S.
  • There are more apps for the android platform out there than I realized at first. It’s also possible to download apps from anywhere. This makes it possible for developers to sell their apps on alternative app stores, or even on their own websites. I’ve purchased a few android apps this way.
  • The lack of trackball is made up for by the existence of arrow keys on the trackpad.
Posted in Mobile phones | Tagged , | Leave a comment

Slice ‘em thin, love ‘em more.

Thin slicing and starting with the simplest thing that could possibly work is motivating. I do not have to wait too long for gratification, since I am frequently witnessing useful code getting out the door.
Lack of gratification lends a lack lustre feel to a coding stint.
In a recent incident, I felt that too much time had passed since the last compile. It was taking too much time to make a new test pass. The lack lustre experience kept nagging me, until I realized later that test was too long. The entire test lay insidiously on a single line, but tested too much for me to thin slice the code to make it pass quickly.
In this case, I believe I should have built a thin test, passed it, and iteratively expanded it. It wasn’t a large test in itself. Implementing the code behind it was just more than I could handle at the time, late at night, tired and enthusiastic. Slicing the test would have made it easier to think about the implementation. The exercise would probably have taken less time, and been more gratifying. I see that now.

Posted in Software Development | Tagged , | Leave a comment

I’m learning to make my tests more effective

Recently I’ve been chewing on a small pieces of code, doing tdd just for practice, trying to see what works, what keeps it going. Here are some points that have helped so far.

  • Am I afraid of breaking my tests? Is “fixing the tests” a chore? If so, there’s usually something wrong with the tests. Maybe Rigidity, Fragility, Immobility, Viscosity, Needless Complexity, Needless Repetition or Opacity. Or some of them.
  • What’s keeping me from my next compile? It’s probably something I’m thinking about too far ahead. I’m writing a lot of code without tests to match. I shouldn’t get too far ahead of my tests. I should backtrack and start again with smaller tests to start compiling regularly again.

These two help me take smaller steps. Smaller steps help me watch my design unfold in slower motion, making it easier to spot problems, among other things.

Posted in Software Development | Tagged | Leave a comment