Tahir Hassan's Blog

My Technical Notes

Monday, 19 February 2018

Downloading to MP3 using `youtube-dl`

Using the command-line utility `youtube-dl`, do:

youtube-dl --extract-audio --audio-format mp3 <video URL>

In order to make this work, download `ffprobe.exe` and add it to the `PATH` environment variable.

Thursday, 8 February 2018

TortoiseGit: Pushing after combining at tip

After using "Combine to one commit" on pushed commits at the tip, in order to push them, you have to use the `--force`, so either:

git push --force

Using the UI, do `TortoiseGit` → `Push...`, and in the dialog, select `unknown changes`, which does the same thing as `--force`.


Wednesday, 7 February 2018

Very Simple API Versioning in Web API

I am using Web API 5 (using .NET framework). Use the `RoutePrefix` attribute to stick a version `v<num>` in the URL. I am using the out of the box `ValuesController` that comes out of the box:

public class ValuesController : ApiController
    public static IList<string> _Values = new List<string> { "Jeremy", "Bernie" };

    // GET api/v2/values
    public IEnumerable<string> Get()
        return _Values;
    // GET api/v2/values/5
    public string Get(int id)
        return _Values[id];

    // POST api/v2/values
    public void Post(string value)

    // PUT api/v2/values/5
    public void Put(int id, string value)
        _Values[id] = value;

    // DELETE api/v2/values/5
    public void Delete(int id)

Adding Swashbuckle/Swagger to a Web API solution

I am using Web API 5 (the version of `Microsoft.AspNet.WebApi` NuGet package is 5.2.3).

In NuGet console, run:

Install-Package Swashbuckle

This add the required assembly references and adds a `SwaggerConfig.cs` which registers `/swagger` as the user interface URL for Swagger.

Swagger uses an XML documentation file, therefore in the Build tab in the project properties, for both `Debug` and `Release` configurations, make sure `XML documentation file` is ticked.

Thursday, 25 January 2018

Creating a Tag in Git

It is recommended to create an "annotated" tag, rather than a normal one:

git tag -a v1.0.3 -m "my version v1.0.3"

Afterward you push the tags:

git push --tags

Friday, 12 January 2018

Creating a basic TypeScript project in Visual Studio Code

These are very simple instructions to create a bare-bones project for learning TypeScript using Visual Studio Code. Use the Integrated Terminal to execute the commands.

First create a directory that will contain the project. Within the directory, create the required (by npm to manage its packages and debug it) `package.json` file by doing:

npm init --yes

This creates the package.json file without prompting (`--yes`).

Thereafter, install the type information for `node`:

npm install @types/node --save-dev

Thereafter, use `tsc` to create the `tsconfig.json` which is required by VSCode to compile the TypeScript files:

tsc --init

Add a `main.ts` file, although you could give this file any name.

Within `tsconfig.json` set `sourceMap` and `watch` to `true`. Also add the following after the `compilerOptions` element:

"files": [

After writing some code in `main.ts`, you first have to compile it, after which you can debug it. Do Ctrl-Shift-b to build, then F5 or run it from the Debug menu.

Thursday, 11 January 2018

Ubuntu: Setting the keyboard layout to UK

In Bash, do:

setxkbmap -layout gb