Tahir Hassan's Blog

My Technical Notes

Work Blog

Tuesday, 9 February 2016

Git - network drive path syntax

Following is an example network path:


  • it starts with `file://`
  • the rest of the path is just the normal windows path

Monday, 1 February 2016

F# Unit Testing

Because there is no "Unit Test Project" template for F#, we have to set it up ourselves:

  • Create a Class Library Project
  • Add a reference to `Microsoft.VisualStudio.QualityTools.UnitTestFramework`
  • To create a test class, we only need to decorate our classes and methods with attributes from the above unit testing DLL reference:

Friday, 29 January 2016

Thursday, 28 January 2016

MsTest: Testing private methods

A few years ago, MsTest had the Private Accessor feature, but it has been deprecated.

The apparent solution now is to use the `InternalsVisibleToAttribute` within your application code assembly:

After this, all our `internal` methods will be visible to the `MyProject.Tests` assembly.

Friday, 22 January 2016

*.url path handler in Chrome

Internet Explorer stores its favourites in the file system, with each link being a separate file.

In order to allow ourselves to access the same bookmarks within Firefox, we first navigate to favourites folder `file:///.../Favourites/` Within there, we can click on the `*.url` file links.

However, Chrome does not handle `*.url` files in the same way. It displays the textual contents of the `.url` file rather than following its URL. The solution is to implement a Tampermonkey script handling URLs ending in `.url`.

But first we must allow Tampermonkey access to the local file URLs. Below is the user script that handles `*.url` file extensions:

Tampermonkey: Enabling it to work on file:/// paths

Click clap on hamburger menu button, then Settings, then click on Extensions on the left, then check `Allow access to file URLs`.

Tuesday, 5 January 2016

AutoHotkey: Dealing with a SAFEARRAY(BSTR) array from COM

In my COM (Component Object Model) interface, I have a `Suggestions` property that is of the .NET type `string[]`; here is the COM type information (found using OLEView):

After invoking the getter:

we can first check if the array is empty by checking if the `_MaxIndex()` is `-1`:

If there are elements, then `_MaxIndex()` will return a value greater than or equal to `0`.

To get the last element, we pass the `_MaxIndex()` value to the indexer:

This is very simple, but one bit of code in which it does NOT work is using the indexer on the COM object's property:

For whatever reason, we must first evaluate `obj.Suggestions`, and then call the indexer. Therefore this works:

In general, when getting the array, because we are dealing with a copy of the data, if you are using this data multiple times in the code, it is best to assign it to variable before to avoid producing it multiple times.