[manjaro] Make C# debugger work in Visual Studio Code

Problem
Under Manjaro / Arch you use Visual Studio Code with the C# extension. Everything works fine except the C# debugger.

Solution
I found the solution here: https://github.com/OmniSharp/omnisharp-vscode/issues/1323 . The debugger on Manjaro / Arch is not supported officially, so we need to do some tricks. In VS Code open the user settings and add this line:

"csharp.fallbackDebuggerLinuxRuntimeId": "ubuntu.16.04-x64"

Uninstall the C# extension, restart VS Code, and re-install the C# extension. Open a .cs file and the extension will download some packages, including the debugger for Ubuntu 16.04 (as we specified it in the settings).

However, the *.so files of the Ubuntu debugger rely on a specific version of the package “icu”.

$ cd ~/.vscode/extensions/ms-vscode.csharp-1.11.0/.debugger
$ find *.so -type f | xargs ldd 2> /dev/null | grep not\ found
        liblldb-3.6.so => not found
        libvsdebugeng.so => not found
        libvsbaseservices.so => not found
        libvsbaseservices.so => not found
        libicuuc.so.55 => not found
        libicui18n.so.55 => not found

The last 2 lines are interesting: we need version 55 of the package “icu“. “yaourt icu” revealed that I had version 59 installed, but version 55 can be installed too with “yaourt icu55“. The two versions can co-exist. When installed, restart VS Code and debugging should work now.

Credits
The solution was found at https://github.com/OmniSharp/omnisharp-vscode/issues/1323 . A big thanks for starquake.

Categories: csharp, manjaro Tags:

In C#, ++c and c += 1 are not always equivalent

July 2, 2017 1 comment
csharp> char c = 'a'
csharp> ++c
'b'
csharp> c += 1
(1,7): error CS0031: Constant value `1' cannot be converted to a `char'
csharp>
Categories: csharp Tags: ,

Getting started with C# on Linux

June 30, 2017 Leave a comment

I’ve heard lots of good things about C# but I’ve never tried it. I saw some codes and thought “fine, it’s like Java”. As I also have Linux on my primary machine, I was not interested in Microsoft technologies. However, a few years ago .NET Core was open sourced and it reached version 1.0 (now it’s 1.1). It’s a cross platform framework and it works well under Linux too, so I thought it was time to try it. Project Mono has also existed for a long time but .NET Core comes directly from Microsoft.

Under Manjaro, install these packages with yaourt: dotnet, dotnet-cli, dotnet-sdk. We will also try Mono, so install the package mono too. For Ubuntu, see the instructions here: https://www.microsoft.com/net/core#linuxubuntu .

Create a project

Create a folder for holding your C# projects, e.g. ~/CSharpProjects (optional), and create a folder for a sample project (e.g. ~/CSharpProjects/Sample). Enter it, and create a source file called hello.cs with the following content:

using System;
using static System.Console;
using System.Linq;

namespace SampleApp
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            WriteLine("Hello World!");
        }
    }
}

Compile with Mono

If you installed Mono, you have the command “csc” (C Sharp Compiler).

$ csc hello.cs
$ mono hello.exe 
Hello World!
$ chmod u+x hello.exe
$ ./hello.exe 
Hello World!

Compile with dotnet

Now let’s use the official command-line tools. You can also delete the file “hello.exe”. I suppose you are in the project’s folder. Issue the following command:

$ dotnet new console

It creates a project file (with extension .csproj), and a sample file called Program.cs . As we already have hello.cs, Program.cs is not needed so simply delete it (leave only one source file, but it doesn’t matter which one). Then,

$ dotnet restore    # installs some necessary packages, using the .csproj project file
Restoring packages for /home/jabba/Dropbox/csharp/Sample/Sample.csproj...
...
$ dotnet run        # compile and run
Hello World!

The binary output is here: bin/Debug/netcoreapp1.1/Sample.dll . If you use the command “dotnet”, you get a .dll, not an .exe . However, it can be executed:

$ cd bin/Debug/netcoreapp1.1
$ ./Sample.dll 
Hello World!
$ dotnet Sample.dll 
Hello World!

When you are ready with the development and ready for deployment, issue this command:

$ dotnet publish
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.

  Sample -> /home/jabba/Dropbox/csharp/Sample/bin/Debug/netcoreapp1.1/Sample.dll

According to the docs, “dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory. The dotnet publish command’s output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution and is the only officially supported way to prepare the application for deployment.”

REPL

Mono ships a REPL too called “csharp”.

$ csharp 
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> 1+1
2
csharp>

Visual Studio Code support

Programming C# with VS Code is a joy. When you open a .cs file, the editor offers immediately to install the official C# extension. In order to execute a program, install the Code Runner extension. Then, add the following lines to your user settings:

    "code-runner.executorMap": {
        // "python": "python3",
        // "csharp": "echo '# calling mono\n' && cd $dir && csc /nologo $fileName && mono $dir$fileNameWithoutExt.exe",
        "csharp": "echo '# calling dotnet run\n' && dotnet run"
    }

Choose either Mono or dotnet.

Summary

If you have Linux, no problem, you can try C#. I started to play with it yesterday, but I like it. It seems a saner language than Java :)

Links

TODO…

download with youtube-dl

June 20, 2017 Leave a comment

For downloading a YouTube playlist, or for downloading all the videos of a YouTube user, I use this script:

URL="https://..."    # youtube user / playlist

youtube-dl --ignore-errors --download-archive downloaded.txt -f 22 "$URL"

The videos will be saved in .mp4 format. You can stop the script and re-run it later. The already saved videos are stored in downloaded.txt and they will be skipped if you re-run the script.

Categories: bash Tags: ,

Robomongo

Robomongo is a native GUI client for MongoDB. So far I’ve used RockMongo, which was perfect for me, but it’s PHP-based and quite hard to install. Also, it seems to be abandoned, the last commit was in 2015. It’s a pity…

Robomongo is simple. Just download, decompress, and launch. It’s free and multi-platform.

Categories: mongodb Tags: , , ,

JSON Path

May 20, 2017 1 comment

I wrote a command-line program that outputs the full path of every key / value in a JSON file.

Example

$ ./json_path.py sample.json
root.a => 1
root.b.c => 2
root.b.friends[0].best => Alice
root.b.friends[1].second => Bob
root.b.friends[2][0] => 5
root.b.friends[2][1] => 6
root.b.friends[2][2] => 7
root.b.friends[3][0].one => 1
root.b.friends[3][1].two => 2

More information at the project’s github page.

Categories: bash, python Tags: ,

streamlink

Streamlink is a command-line utility that allows you to watch online video streams in popular video players, such as VLC, MPlayer or mpv.

(Under Manjaro it’s installable with yaourt.)

Example:

$ streamlink twitch.tv/sscait 
[cli][info] Found matching plugin twitch for URL twitch.tv/sscait
Available streams: 720p_alt, audio_only, 160p (worst), 360p, 480p, 720p (best)

$ streamlink twitch.tv/sscait best

If you just want to listen to it, select “audio_only” instead of “best”. It has lots of options, see the man for more info. For scripting, there is also a “-j” switch to produce a JSON output instead of normal text.

When is it useful? For instance you have a favourite channel that is streaming right now, but you don’t want to open it in the browser. Just launch it from the command-line and watch it in VLC. Or, if it’s a talk show, you just want to listen to it (see “audio_only”).

Categories: bash Tags: , , ,