April 20, 2024

You want both:

  • to stream your cam during a video call
  • and to record the original cam output to a file.

You need to setup Virtual Cam in OBS Studio.

  • OBS Studio will record the original cam video.
  • It will forward the stream to a virtual device.
  • Jitsi will stream the virtual device video.

March 30, 2024

In our exploration of the ways to navigate back to previous buffer positions, Registers can be seen as mark ring items with an assigned name, so that they can be conveniently accessed by that name in an arbitrary order.
But in fact they are much, much more:

  • They can be persisted so they survive reboots.
  • They can resurrect killed buffers.
  • Other than buffer positions, they can contain snippets of text, keyboard macros, windows layouts and even custom values.

Playing Hansel and Gretel is just the excuse to happily slip into yet another rabbit hole.
Let’s go!


March 20, 2024

A cool trick not everybody knows with Visual Studio and JetBrains’ IDEs is that it is possible to navigate back to previous positions with Ctrl -.

A similar trick also works with Bash:

cd -

and with Git:

git checkout -

Neat, right?
Of course, there are way more powerful tools built around this idea (such as z, autojump and zoxide). And — did you doubt? — similar powerful features in Emacs too. Let’s explore them.


March 20, 2024

Rings — fixed sized variables acting as circular buffers — are a beautiful idea: one day I will eventually write something about how undoing changes is handled in Emacs with the undo-ring. I find outrageous that other editors have not followed the same idea.


March 17, 2024

In the previous installment we learnt how to surround a region with hard-coded <<< and >>>. Let’s learn now how to interactively ask arguments to the user and to go beyond hard-coded delimiters.


March 16, 2024

Or: booleans can be very ambiguous without context, as in:

A Prolog programmer is delivering a baby.

The mother asks, “Is it a boy or a girl?”

and the Prolog programmer says: “Yes”.


March 15, 2024

I refuse to see the tension between theory and practice.
I love the sentence:

In theory there is no difference between theory and practice.
In practice there is.

It is very, very funny, I love to cite it when I can. But I cannot help but think it is false — I will write about this, some time.

Let’s talk about mathematical notions. I hear way too many times

Yes, hey are universal and profound. But practically useless.

I hate this.

With this post I challenge myself to debunk this notion. I chose a very abstract notion — the concept of cardinality of types — and challanged myself to find pragmatic uses of it in the everyday programmer’s life.

Can there be a more useless and theoretical notion that cardinality?


March 1, 2024
  1. Select a region.
  2. Let Emacs surround it with custom delimiters.
  3. Profit.

February 24, 2024
  • When a file of type Y is opened, Emacs sets a specific major mode.
  • Each major mode is equipped with a hook, a variable holding a list of functions.
  • After that major mode is activated, all the functions in its hook are run.
  • If you add a function to the mode’s hook it will be run for that kind of file.
  • You can use `add-hook` for that.

Therefore, just use:

(add-hook '<major-mode>-hook #'<function-you-wish-to-trigger>)

For example, to have line numbers in your Python files, use:

(add-hook 'python-mode-hook #'display-line-numbers-mode)

October 30, 2023

Virtually all the tutorials on Monads introduce them only after a lengthy discussion about Functors, and often resorting to intrepid and debatable metaphors.
I dare to take a different path and to go straight to the point, following what Mike Vanier did in his seminal 8-post series Yet Another Monad Tutorial.

I challenged myself to write a post that:

  • prioritizes code over storytelling
  • uses no metaphors (no boxes, no burritos)
  • does not require Category Theory
  • jumps past the discussion why Functional Programming is valuable
  • does not follow the classical Functors -> Monads narrative
  • is tailored for C# developers and digestible by Java ones

August 29, 2023

This is an appendix of You probably don’t need MediatR: it offers practical guidance to implement the MediatR’s functionalities using a plain object-oriented approach.

It goes through all the examples in the MediatR readme file and all the snippets in the ‘samples’ project: for each of them, it provides an implementation based on OOP standard patterns, together with some design considerations.


August 10, 2023

It’s no secret that getting started with Property-Based Testing (PBT) is hard. This series of articles does not have the presumption of changing this fact. It is merely the outcome of the observations and thoughts I have gathered during my personal journey.
By no means is this a comprehensive manual. Consider it as a friendly introduction to help dispel the fear.

I will rely on C# examples with FsCheck, although my heart is with Hedgehog.
All the code samples are on GitHub.

Note: do you prefer to start directly with a practical example? Go straight with the 4th installment.


January 14, 2023

Did you know Bash has got macros, a multi-clipboard, an undo feature, and a word completion based on history?

If you prefer watching videos to reading posts, you can check it out here.


November 28, 2022

TL;DR

  • Even without squashing, Pull Requests already include a squashed commit
  • You can get an on-the-fly squashed view of history using --first-parent
  • Squashing would not save space
  • Squashing makes git bisect less effective
  • Once squashed, details are lost forever
  • Joining is easier than separating
  • Squashing may promote sloppy habits
  • Don’t squash, rebase

November 24, 2022

Or: how I learnt to stop resetting the DB after each integration test.

TL;DR

  • Cleaning database tables after each integration test is not stictly needed
  • It’s often not even desirable
  • Tests can be easily made independent from the initial DB state and from each other
  • Just use unique identifiers and avoid absolute asserts

  • Tests designed like this can be run in parallel
  • They run faster
  • And they are more resilient and realistic

August 11, 2022

A tattoo with the Y Combinator

What the heck is that? That’s the Y Combinator!
Uh? A higher-order function with which anonymous lambdas can be made recursive.
Sounds useful, I guess? No, it’s not. It’s a purely intellectual challenge.
Any practical application for my C# developer daily life? Not at all.
So, what’s the point? Why? Because it’s fun.


August 2, 2022

Variables are just syntactic sugar for lambda expressions: they are not stricly necessary and ideally C# could happily live without them. Even the reseved word var could be eliminated.

In this post we will use ReSharper for refactoring variables away, transforming them to anonymous lambda expressions.

That’s a trick that will come in handy for deriving the Y Combinator.


May 30, 2022

git stash is very convenient to quickly switch to another branch without loosing your changes.
What if you wish to browse both your changes and another branch?
worktree lets you checkout more than one branch at a same time.


January 23, 2022

Could you explain the following?

[Test]
public void puzzling_test()
{
    IEnumerable<string> strings = SomeStrings;
    Assert.AreEqual(new[] { "Foo", "Bar", "Baz" }, strings.ToArray());

    var test1 = strings.Select(s => new string(s.ToCharArray()));
    Assert.AreEqual(new[] { "Foo", "Bar", "Baz" }, test1.ToArray());

    var test2 = strings.Select(s => "" + new string(s.ToCharArray()));
    Assert.AreEqual(new[] { "Foo", "Bar", }, test2.ToArray());
    // Hey, what happened to Baz??

    try
    { 
        var test3 = strings.Select(s => new string(s.ToCharArray()) + "");
        Assert.Null(test3.ToArray());
    }
    catch (PlatformNotSupportedException)
    {
        Assert.Pass();
    }
            
    var test4 = strings.Select(s => new string(s.ToCharArray()) + "");
    Assert.AreEqual(new[]
    {
        "Argument Foo of type System.String is not assignable to parameter type int32",
        "Argument Bar of type System.String is not assignable to parameter type int32",
        "Constructor 'Baz' has 0 parameter(s) but is invoked with 0 argument(s)"
    }, test4.ToArray());
}

December 18, 2021

MediatR is a very popular library used to reduce dependencies between objects. It advocates an architecture based on very valuable design principles:

  • not allowing direct communication beetween objects, it promotes loose coupling
  • it leads toward a Message-Oriented Architecture
  • it supports an asynchronous in-process messaging
  • it promotes reuse object

December 16, 2020
December 8, 2020
  • A C# classe can implement an interface either implicitly or explicitly
  • Implement explicitly wherever possible: it is a good practice
  • In fact, there are rare cases for Implicit Implementation.
  • Indeed, objects should be manipulated solely in terms of their interface, not in terms of their concrete types.

  • With Explicit Implementation methods can be internal, which is good for encapsulation
  • Explicit Implementation is a design best practice, as it promotes Loose Coupling and enforces the Dependency Inversion Principle.
  • It gets rid of Ghost Public Methods, promoting maintenaibility

November 26, 2020

Deriving the Y-Combinator from a recursive implementation of factorial


September 12, 2020

The following code is just legit:

class Foo
{
    private string _privateField;
    
    void DoSomething(Foo anotherInstance)
    {
        anotherInstance._privateField = "doh!";
    }
}

April 23, 2020

This post describes a possible approach for registering components with circular dependencies (e.g. Foo needs Bar, and Bar needs Foo) with Autofac, with both components taking their dependencies through their constructor (the so called Constructor/Constructor Dependencies).

TL;DR

Use an Implicit Relationship Type and inject Lazy<Foo> instead of Foo.


April 10, 2020

git cherry-picks seems to be detaching a commit from its parent and to be attaching it to a new parent. But this is just an illusion: as a matter of fact, cherry-pick moves patches, not commits. That’s why cherry-picking a commit you can have conflicts.

Actually, it’s simpler that it seems. Bear with me.


October 9, 2019

Some tools and Git hosting services promote the addition of pre-baked .gitignore files to repositories at their creation.
GitHub, for example, offers the option to add long, 300+ lines, pre-compiled .gitignore files with a single click.

While initializing a repository with a README and a License is a very good idea, using pre-baked .gitignore files isn’t. It violates YAGNI and it may cause puzzling situations.

A better alternative is a global .gitignore file.


May 9, 2019
Setup a one-node, private Ethereum network in a Docker container.
December 8, 2018

So, by using lambdas in the Fluent Builders our tests started containing expressions such as:

    var order = new OrderBuilder()
        .WithNumber(10)
        .WithDate(new DateTime(2018, 12, 24))
        .HavingArticle(a => a
            .WithPrice(32.50m)
            .WithCategory("books"))
        .HavingCustomer(c => c
            .WithName("Amelia"))
        .Build();

We found that this improved the readibility of tests, making them a bit more intelligible by non-technical people.

While the goal was not to implement BDD tests – which are more conveniently written with specialized libraries – we felt that the tests could benefit from having an even more fluent syntax, possibly using language closer to domain than to the technical implementation.


December 8, 2018
    var order = AnEmptyOrder()
        .WithNumber(10)
        .CreatedOn(new DateTime(2018, 12, 24))
        .ByACustomer(c => c
            .Named("Amelia")
            .Aged(42))
        .ContainingAnArticle(a => a
            .WithPrice(32.50m)
            .InCategory("books"))
        .Build();

We show how we designed our C#, domain-focused, fluent builders that support nested entities by using lambdas.


May 10, 2018

SICP doesn’t cease to amaze me. Here’s a challenge for you to solve, which I found in the chapter Building Abstractions with Data. I will provide a solution in C#.

The quiz is:

Would you be able to implement a 2-tuple (a pair) of integers, only leveraging functions and lambdas, without using neither variables nor class fields?


May 5, 2018

While reading Structure and Interpretation of Computer Programs, I got hit by this sentence (p. 65):

“A let expression is simply syntatic sugar for the underlying lambda expression”

It claims that variables definition is not a necessary language feature, and that it has been introduced only as a convenient alternative to lambda expressions.

WAT? Seriously?


May 5, 2018

While reading Structure and Interpretation of Computer Programs, I got hit by this sentence (p. 65):

“A let expression is simply syntatic sugar for the underlying lambda expression”

It claims that variables definition is not a necessary language feature, and that it has been introduced only as a convenient alternative to lambda expressions.

WAT? Seriously?


October 11, 2017

You might have noticed that after a fresh MiniShift installation the admin user cannot see system projects openshift, openshift-infra, kube-public, kube-system and default, so, trying to switch to one of them results in an error:

$ oc login -u admin -p admin
$ oc project openshift
error: You are not a member of project "openshift".
You have one project on this server: My Project (myproject)
To see projects on another server, pass '--server=<server>'.

December 7, 2016
If you are learning to touch type, use this cheat sheet. Print it, and forget the keyboard.


November 21, 2016

Registering components in Autofac is straightforward, as long as no primitive dependencies (such as connection strings, URLs and configuration parameters in general) are involved.
This post describes the strategy for dealing with primitive dependencies.