Thursday, 26 October 2017

How to save paths from Search results in Windows Explorer

From time to time I want to document location(s) of some file on my system. I usually use Total Commander which has built-in functionality of copying the paths of selected files but it is possible to achieve the same in good old Windows Explorer. Once search is complete and all results are displayed, select them all with CTRL+A, hold down SHIFT key and do the right click anywhere on the selection. In the context menu which appears, find and click on Copy as path. All paths are now copied in the clipboard.


Now I can paste all paths:


"C:\Windows\SysWOW64\ucrtbase.dll"
"C:\Windows\WinSxS\wow64_microsoft-windows-ucrt_31bf3856ad364e35_10.0.16299.15_none_d9020b8bbf051ead\ucrtbase.dll"
"C:\Windows\System32\ucrtbase.dll"
"C:\Windows\WinSxS\amd64_microsoft-windows-ucrt_31bf3856ad364e35_10.0.16299.15_none_cead61398aa45cb2\ucrtbase.dll"
"C:\Windows\System32\ucrtbase_enclave.dll"
"C:\Windows\WinSxS\amd64_microsoft-onecore-i..atedusermode-common_31bf3856ad364e35_10.0.16299.15_none_215b207fb180b0b9\ucrtbase_enclave.dll"
"C:\Program Files (x86)\Microsoft Visual Studio 15.0\Team Tools\Performance Tools\ucrtbase.dll"
"C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x86\ucrtbase.dll"
"C:\Program Files (x86)\Microsoft Visual Studio 15.0\Team Tools\Performance Tools\x64\ucrtbase.dll"
"C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64\ucrtbase.dll"
"C:\Program Files\Microsoft Visual Studio 15.0\Remote Tools\DiagnosticsHub\ucrtbase.dll"
"C:\Program Files\Microsoft Visual Studio 15.0\Team Tools\DiagnosticsHub\Collector\ucrtbase.dll"
"C:\Windows\WinSxS\Backup\wow64_microsoft-windows-ucrt_31bf3856ad364e35_10.0.16299.15_none_d9020b8bbf051ead_ucrtbase.dll_a00b9625"
"C:\Windows\WinSxS\Backup\amd64_microsoft-windows-ucrt_31bf3856ad364e35_10.0.16299.15_none_cead61398aa45cb2_ucrtbase.dll_a00b9625"
"C:\Users\bojan\AppData\Local\Microsoft\OneDrive\17.3.7073.1013\ucrtbase.dll"

How to install Plugin Manager in Notepad++

I wanted to install a new plugin for Notepad++ via its Plugin Manager (which is plugin itself) but when I clicked on Plugins in the main menu I realized that Plugin Manager was missing. To install it, I did the following:

Go to Plugin Manager releases page and download the latest one. At the time of writing it was v1.4.9 so I downloaded file PluginManager_v1.4.9_UNI.zip.

Unpack the zip file. The content of the archive is:


..\PluginManager_v1.4.9_UNI\plugins
..\PluginManager_v1.4.9_UNI\plugins\PluginManager.dll
..\PluginManager_v1.4.9_UNI\updater
..\PluginManager_v1.4.9_UNI\updater\gpup.exe



Find the location of the Notepad++ installation on your machine. In my case, it was: C:\Program Files (x86)\Notepad++.



Copy ..\PluginManager_v1.4.9_UNI\plugins\PluginManager.dll to C:\Program Files (x86)\Notepad++\plugins and ..\PluginManager_v1.4.9_UNI\updater\gpup.exe to C:\Program Files (x86)\Notepad++\updater.

Restart the Notepad++. Plugin Manager now appears in the list of plugins.



Friday, 28 April 2017

How to build Chromium on Ubuntu


I followed official instructions and, with minor modifications, managed to build and run Chromium on 64-bit Ubuntu 16.04. Entire process on PC with Intel i7 with 16GB RAM takes couple of hours. I had Git and Python installed already so went straight into the process:

Clone depot_tools repository (this was in my ~/dev directory):

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git


The next step was to append depot_tools path to to PATH. I first tried:

$ export PATH="$PATH:~/dev/depot_tools"


This made running install-build-deps.sh script to fail as described here. I therefore applied suggestion from that forum thread and used the path in the following form:

$ export PATH="$PATH:${HOME}/dev/depot_tools"


Create directory for Chromium source code

$ mkdir chromium
$ cd chromium


Check out the code (without the full repo history) and its dependencies:

$ fetch --nohooks --no-history chromium


Fetch creates scr directory:

$ cd src


Install additional build dependencies:

$ ./build/install-build-deps.sh


Run hooks which fetch additional binaries:

$ gclient runhooks


Create a build directory:

$ gn gen out/Default


Set gn arguments in order to speed up build. The following command will open a config file in vi editor:

$ gn args out/Default


I added the following lines:

enable_nacl=false
symbol_level=1
emove_webcore_debug_symbols=true


Build Chromium:

$ ninja -C out/Default chrome


Run built Chromium executable:

$ ./out/Default/chrome


Et voila! Chromium opens:



NOTE: I didn't install Google API keys and this is the reason for the notification which appears in the browser.

Wednesday, 26 April 2017

How to add a NuGet package to C# project in VSCode on Ubuntu

In VSCode open Terminal and use dotnet CLI command package and specify the name of the desired package (e.g. Newtonsoft.Json):


$ dotnet add package Newtonsoft.Json



This will add a reference to that NuGet package in project:



Output in VSCode:


This can be verified in the project file:



VSCode notifies us that there are unresolved dependencies:


If we click on Restore newtonsoft.json library gets downloaded to ~/.nuget/packages directory.

After resolving them we can start using object from the newly added package. Intellisense also works for new dependency assembly:


Sunday, 23 April 2017

Strategy Pattern

Problem:

Context has to be able to apply different Algorithms (strategies, actions, behaviours) in the runtime but is coupled with their implementations. It contains all possible concrete implementations of an Algorithm family and has to change if:
  • implementation of some Algorithm has to change
  • a new Algorithm has to be added or some existing has to be removed
This breaks Single Responsibility Principle (Context has to change for more than one reason) and Open-Closed Principle (Context has to be modified if list of Algorithms gets extended).

Solution:

Remove Algorithm implementations out of the Context and separate them in their own classes which implement new interface IStrategy with method DoAlgorithm(). Introduce lookup table (Dictionary) which keeps all IStrategy implementations. When Context receives key from the input, it looks up the Dictionary and calls IStrategy implementation which matches the given key.

References:

Strategy pattern
Applying Strategy Pattern Instead of Using Switch Statements
Strategy

Saturday, 22 April 2017

How to run .NET Core console application in VSCode on Ubuntu


In the previous article I demonstrated how to create simple .NET Core "Hello, world!" console application and here I want to show how can we load, run and debug that project in VSCode.

In VSCode, open TestProject directory. All generated files are shown in the left pane. VSCode downloads and installs required packages:




Required assets are standard VSCode JSON files so after we answer Yes to the first question .vscode directory appears:


Clicking on Restore triggers restoring packages:


If we hit F5, VSCode will execute the program:


We can set the breakpoints as well:


How to create .NET Core Console application on Ubuntu


To create .NET project of desired type we can use .NET Core command line tool (dotnet). Let's see the list of all possible project types:

$ dotnet new

Template Instantiation Commands for .NET Core CLI.

Usage: dotnet new [arguments] [options]

Arguments:
template The template to instantiate.

Options:
-l|--list List templates containing the specified name.
-lang|--language Specifies the language of the template to create
-n|--name The name for the output being created. If no name is specified, the name of the current directory is used.
-o|--output Location to place the generated output.
-h|--help Displays help for this command.
-all|--show-all Shows all templates


Templates Short Name Language Tags
----------------------------------------------------------------------
Console Application console [C#], F# Common/Console
Class library classlib [C#], F# Common/Library
Unit Test Project mstest [C#], F# Test/MSTest
xUnit Test Project xunit [C#], F# Test/xUnit
ASP.NET Core Empty web [C#] Web/Empty
ASP.NET Core Web App mvc [C#], F# Web/MVC
ASP.NET Core Web API webapi [C#] Web/WebAPI
Solution File sln Solution

Examples:
dotnet new mvc --auth None --framework netcoreapp1.1
dotnet new classlib
dotnet new --help

To create Console application project we have to use console:
$ dotnet new console -o TestProject -n HelloWorld
Content generation time: 54.4945 ms
The template "Console Application" created successfully.

This creates a directory TestProject and in it project named HelloWorld and intial source code file:
$ ls
TestProject

$ cd TestProject/

/TestProject$ ls
HelloWorld.csproj Program.cs

HelloWorld.csproj:
/TestProject$ cat HelloWorld.csproj


Program.cs:
/TestProject$ cat Program.cs


Let's now update dependencies (NuGet packages) and tools specified in the project:
/TestProject$ dotnet restore
Restoring packages for /home/bojan/Downloads/test/TestProject/HelloWorld.csproj...
Generating MSBuild file /home/bojan/Downloads/test/TestProject/obj/HelloWorld.csproj.nuget.g.props.
Generating MSBuild file /home/bojan/Downloads/test/TestProject/obj/HelloWorld.csproj.nuget.g.targets.
Writing lock file to disk. Path: /home/bojan/Downloads/test/TestProject/obj/project.assets.json
Restore completed in 492.24 ms for /home/bojan/Downloads/test/TestProject/HelloWorld.csproj.

NuGet Config files used:
/home/bojan/.nuget/NuGet/NuGet.Config

Feeds used:
https://api.nuget.org/v3/index.json

This creates obj directory and various config files:
/TestProject$ ls
HelloWorld.csproj obj Program.cs

/TestProject$ cd obj/

/TestProject/obj$ ls
HelloWorld.csproj.nuget.g.props HelloWorld.csproj.nuget.g.targets project.assets.json

HelloWorld.csproj.nuget.g.props:
/TestProject/obj$ cat HelloWorld.csproj.nuget.g.props


HelloWorld.csproj.nuget.g.targets:
/TestProject/obj$ cat HelloWorld.csproj.nuget.g.targets


project.assets.json:
/TestProject/obj$ cat project.assets.json


We can now build the project and run the binary output:
/TestProject$ dotnet run
Hello World!

This command built the project and placed binary output and other build artifacts in newly created bin directory:
/TestProject$ ls
bin HelloWorld.csproj obj Program.cs

/TestProject$ cd bin

/TestProject/bin$ ls
Debug

/TestProject/bin$ cd Debug/

/TestProject/bin/Debug$ ls
netcoreapp1.1

/TestProject/bin/Debug$ cd netcoreapp1.1/

/TestProject/bin/Debug/netcoreapp1.1$ ls
HelloWorld.deps.json HelloWorld.dll HelloWorld.pdb HelloWorld.runtimeconfig.dev.json HelloWorld.runtimeconfig.json

.deps.json (dependencies JSON file) lists dependencies of the application:
/TestProject/bin/Debug/netcoreapp1.1$ cat HelloWorld.deps.json


.runtimeconfig.dev.json:
/TestProject/bin/Debug/netcoreapp1.1$ cat HelloWorld.runtimeconfig.dev.json


.runtimeconfig.json file specifies the shared runtime and its version for the application:
/TestProject/bin/Debug/netcoreapp1.1$cat HelloWorld.runtimeconfig.json


It might seem unexpected that the binary output is not .exe but .dll. This is because default .NET Core's deployment model is Framework-dependent deployment, where output assembly contains only compiled source and 3rd party dependencies but not .NET Core dependencies - assembly assumes that .NET Core Framework and runtime are installed on the target machine. This is why we have to use dotnet tool to run it:

/TestProject/bin/Debug/netcoreapp1.1$ dotnet HelloWorld.dll
Hello World!

The other type of deployment is Self-contained deployment in which case the output assembly is .exe and contains .NET Core dependencies and runtime - nothing else is necessary to be installed on the target system.


References:

.NET Core application deployment
.NET Core command-line interface (CLI) tools