Tahir Hassan's Blog

My Technical Notes

Tuesday, 24 November 2015

Calculating Salary

The following PowerShell Function will calculate your Tax, National Insurance and Pension contributions and tell you your net salary. Not that it only works for salaries between £10,600 and below the 40% tax threshold, £42,385.

We call the function with a gross amount:

Thursday, 5 November 2015

TypeScript Info

A quick note, within NuGet, you can search for TypeScript type definition files by using the term `tag:typescript`.

Monday, 2 November 2015

SQL PIVOT Statement

Given tabular data:

we can turn it into tabular using the following SQL Statement:

The result:

The `PIVOT` statement expects an aggregate function, which we use over the value column. Instead of using `MAX` we could have used `MIN`. The only time that the aggregate function comes in, is when we have multiple rows with the same `UserName` and `ColumnName`. Given the dataset below:

we expect the `ComputerName` for the user to be `ZZZZZ` because we used `MAX`.

Thursday, 22 October 2015

Implementing an Images Controller in MVC

Aim - Given a request of the form `/Images/<path>`, for e.g. `/Images/path/to/garden.jpg`, pass control to a controller-action method `ImagesController.SendFile`.

In your `RouteConfig` class, `RegisterRoutes` method, put the below code immediately

In the `system.webServer/handlers` section we add a handler for paths `Images/*` to prevent IIS from attempting to fetch an image at that file location, which would result in a `404`.

Above, I have set the type to `System.Web.Mvc.MvcHandler`, but even if the `type` attribute was set to a newly-created, "blank" `IHttpHandler` class, control would still be passed to our `ImagesController` class.

Finally we have the `ImagesController` which handles the image request:

Here is the definition of `HttpCache` attribute. If we don't set the HTTP `Expires` header to a time in the future, Firefox (version 41.0.2 at time of writing) will reissue the request, so, in effect, the image is downloaded twice.


Friday, 16 October 2015

Parsing UK Date using Javascript

Monday, 12 October 2015

Javascript: Setting property using its string name

For this example, check the console log output.

Angular $routeParams Example

Running `.../index.html#/person/Tahir/Hassan` will give us the message:

Another method would be to use the HTTP style parameters: `.../index.html#/person?forename=Tahir&surname=hassan`.