Tahir Hassan's Blog

My Technical Notes

Thursday, 29 January 2015

Reasons to use LibreOffice/OpenOffice Draw for Diagramming

Reasons to use Draw

Draw is a great tool to draw diagrams in, and is in fact much better than Dia.

  1. It can handle the pasting of images (Dia can't).
  2. It has connectors, therefore you can move boxes around and the connectors will follow suit.
  3. You can label the connectors. This is a bit like a labelled-edge in graph theory. This is something that Dia can't do apparently, even though it is a specialist diagramming tool.
  4. It is free.

Reasons not to use Draw

  1. The placement of the labels of the connectors. If you draw a massive U-shaped edge, then the label will sit vertically in the middle of the U, whereas I would want it towards the bottom.
  2. In line with the above point, there is no way of moving the label of the edge, so in looping edges, you cannot visually marry the edge with the label.


  1. Display the grid using `View` → `Grid` → `Display Grid`.
  2. Change the font to be, by default, 12px large. Do this by going to `Format` → `Styles and Formatting`. Right click on the `Default` style (should be at the top) and click `Modify`. Go to the `Font` tab and change the size to 12px.
  3. Set the line color to black (from blue).
  4. Set the fill color to white (from blue).
  5. Set the page properties. Go to `Format` → `Page`:
    1. Set the format to `A3`. This should be large enough.
    2. Set the orientation to landscape - my preferred page orientation for diagrams.

Wednesday, 28 January 2015

An Example XML/XSD Pair

In the following xsd, the first (root) element expected is called "example" - of type `example`. `example` requires an element "firstElem" and an attribute "myAttr", both of type `xs:string`.



In the `xsi:schemaLocation` attribute, we specify a schema (or namespace) and then where to find the corresponding xsd file. In general: If you want to give the path to multiple xsd files, we do: For example:

Tuesday, 27 January 2015

Deleting all tables from an SQL Server Database

The SQL is:

In a C# context, we can write the following code to do it:

Friday, 23 January 2015

Making Fsi.exe callable on the command line

There are multiple ways of doing this. Below is the method I prefer:

  • First create a folder in which you will store your commandline application shortcuts. I am going to call the folder `pathlinks`.
  • In your `pathlinks` folder, add a bat file called `fsi.bat` and include the following code:

    `@` suppresses echoing the command to the invoking shell. The quotations `""` prevent white space being interpreted as argument delimiters. `%*` pastes any arguments to the batch file, to the quoted executable instead.

  • Lastly, we include the `pathlinks` folder on the `PATH` environment variable. We can do this two ways:
    • Open `Regedit.exe` as administrator and add `C:\...\pathlinks` to `PATH` in either of the following "folders": If you want to change the current users's path, or If you want to change the machine's path.

    • An alternative way, is to execute in an administrator-privileged cmd: You can add the `-m` argument if you want to change the machine's path variable. Otherwise leave it out to change the user's path variable. One issue with this is that it truncates `PATH` to 1024 characters, so the above method might be better.

You can then execute `fsi` on the command line and it will be interpreted to `fsi.bat`.


Wednesday, 21 January 2015

XML Schemas: targetNamespace vs default namespace (xmlns)

Below is a typical `<xs:schema>` element found in an xsd file:

In the above snippet, any type defined in the document, (without a prefix, of course), will reside in the target namespace `http://tahirhassan.blogspot.com`. This is akin to defining a type in C# within a namespace:

In the above snippet, the `Move` type is in the namespace `TahirHassanBlogspotCom`. Here is the equivalent XML Schema definition file:

In the above xsd, we have defined a type `move` in the namespace `http://tahirhassan.blogspot.com`, using the `targetNamespace` attribute. Any XML document which instantiates the `move` type must also "import" the namespace it is in, `http://tahirhassan.blogspot.com`:

If an element has `xmlns="some-ns"` specified, then that element (and all its descending elements, unless specified otherwise) must belong in the namespace `some-ns` In the above example, we specify the namespace to be `http://tahirhassan.blogspot.com`, and the type to be `move`. It's a bit like instantiating our C# class defined above:

If instead we want to go down the prefixing route, we associate a prefix with a namespace (e.g. `thb` ); we then prefix all elements in the namespace with this prefix:

There is a reason why that in most XSD schema files, the `xmlns` and `targetNamespace` are the same. It is because we are using types defined in the same document. For example, if I define a type `shoe` (for example):

Then the type `shoe` is in the namespace (`targetNamespace` element) `urn:tahirhassan:shoeexample`. If we need to use this type elsewhere in the document:

Then if we did not include the `xmlns`, then the xml parser will be looking for the type `shoe` in the default namespace (and it will not be found). However, since we have specified that the `xmlns` is `urn:tahirhassan:shoeexample`, it will first look for `shoe` in `urn:tahirhassan:shoeexample` before looking anywhere else.

To conclude, all (non-prefixed) types defined in a document will be in the namespace declared in `targetNamespace`. The reason why we also include the `xmlns` attribute is to resolve types found in the document as being in the same namespace.

TODO: Write an article on what `elementFormDefault="qualified"` does.

Tuesday, 13 January 2015

F# - using Formatting Syntax

It is pretty simple to use the print formatting syntax in your own method signature:

Because the lambda is passing its input `s` to `Debug.WriteLine`, we can reduce the above code to:

Source: Printf and Formatting Debug Output in F#

Monday, 15 December 2014

Use of Regex Replace method

I needed to replace all instances of `a.AddressLineX` with `COALESCE(a.AddressLineX, '')`. Here is the code I came up with:

A few things to note: `${1}` can be replaced with `$1`, but it is handy to remember because we might want to write a digit after the group, so we write `${1}1`, not `$11`. Secondly, in PowerShell, to escape the single quote character, we double them up, like in SQL.