Author Archive Mogens

ByMogens

Open source update

As part of daily work, little code snippets and useful bits crystallize and turn out to be so useful that it would be a shame not to share it with anyone.

Yesterday, two new small and focused projects were added to rebus-org: Owino and Swindler.

Owino

Owino is a NuGet package with OWIN extensions. At the moment, it has one single extension method: RegisterForDisposal, which is an extension method on IAppBuilder. You can use it like this:

public void Configuration(IAppBuilder app)
{
    // we're using Windsor
    var container = new WindsorContainer();

    // we're doing stuff
    // (...)

    // we ALWAYS dispose our IoC containers after use
    app.RegisterForDisposal(container);
}

which then ensures that the container is properly disposed when the application shuts down – no matter if the OWIN endpoint is hosted in-process, in an IIS, in a test, or somewhere else.

Swindler

Yesterday Jeremy Miller talked about having to juggle AppDomains in order to properly test code that relies on ConfigurationManager.

You don’t have to pull out the big gun to shoot that tiny bird though, because it IS possible to have the current AppDomain load another app.config – it just requires some tweaking of some private static fields in ConfigurationManager and some other places.

Swindler makes that part easy, because you can just do this:

[Test]
public void SomeTest()
{
    using (AppConfig.Use("my.custom.app.config"))
    {
        // ConfigurationManager will load app settings,
        // connection strings, and custom sections from
        // my.custom.app.config in here
    }
}

which then provides a way to actually test that you can pick up app settings, connection strings, and any custom configuration sections that you might have created.

Where to get it?

They’re both MIT-licensed and can be downloaded from the following places:

ByMogens

Sometimes, it’s the little things…

Lately, I’ve been messing around with making small CLI apps quite a bit. I use it to perform various backend tasks on a couple of cloud-hosted APIs, which has turned out to be a really nice way of automating backend tasks while not needing to build any kind of graphical UI for them.

The other day I wanted to be able to manage user accounts from the command line as well, which required me to input a password to the CLI app somehow – but how to do that without passing the password on the command line?

If I had to do it like this, I would make the password part of that particular console window’s history:

C:\> whatever createuser -user [email protected] -password nooneMustSeeThis!!

which would pose a general security risk. An obvious way to fix that, is to have the CLI app prompt the user for the password, allowing me to enter the password at runtime:

C:\> whatever createuser -user [email protected]

Creating user '[email protected]'

Please enter password: nooneMustSeeThis!!

...

While this is better than accepting it directly as a parameter, it is still not totally acceptable, because the password will be perfectly visible in the console window’s buffer history.

Usually, when prompting the user for a password, we let UIs output little asterisks as a placeholder for each character – and that is of course what we should do 🙂

And that is what I made a small (the smallest one I have made to this date) NuGet package called “Shtern”, which contains one single static method: Password.ReadLine().

With Sthern, the password input scenario would look like this:

C:\> whatever createuser -user [email protected]

Creating user '[email protected]'

Please enter password: *******************

...

while of course delivering the password string to the application. And that was exactly what we needed 🙂

As usual, the code is on GitHub and the package is on NuGet.org.

ByMogens

Tababular

Sometimes it’s nice to be able to work with text, especially when you’re building command-line applications. I usually end up with a bunch of little text formatting helper methods, and recently I made one that could format a JSON array as a nice ASCII table.

I figured that this could be of use to other people as well, so I pulled it out, cleaned it up, added a few nifties, and made it into a NuGet package: Tababular (the code is on GitHub as usual).

First you

Install-Package Tababular -ProjectName YourProject

and then you can do this:

var objects = new[]
{
    new {FirstColumn = "r1", SecondColumn = "hej", ThirdColumn = "hej igen"},
    new {FirstColumn = "r2", SecondColumn = "hej", ThirdColumn = "hej igen"},
};

var text = tableFormatter.FormatObjects(objects);

Console.WriteLine(text);

which will give you something nice to look at:

===============================================
| FirstColumn  | SecondColumn  | ThirdColumn  |
===============================================
| r1           | hej           | hej igen     |
===============================================
| r2           | hej           | hej igen     |
===============================================

and that’s it 🙂

(although there’s a few nice details, like e.g. the ability to properly format multiple lines in cells, etc.)

ByMogens

Rebus FM and open source

It should come as no surprise that we love open source here at Rebus FM – after all, we are building our business around Rebus, which has always had pure open source pumping through its arteries.

We are doing other things too, which we plan to release on the rebus-org organization on GitHub.

If you are working with either Microsoft SQL Server or the excellent PostgreSQL in .NET, you might want to check out our latest addition to the org: Migr8.

Migr8 is a sweet database migration tool that allows for having migrations written as short and sweet scripts, either in C# code or as text files.

It is pretty unique because it supports parallel development of migrations, and thus is the perfect companion if you are working with a git-flow-like workflow where multiple branches are being developed at the same time.

Moreover, Migr8 has now been extended to support PostgreSQL – so, depending on which database you want to use, you can either

Install-Package Migr8 -ProjectName YourProject

or

Install-Package Migr8.Npgsql -ProjectName YourProject

and then start migrating that database.

ByMogens

We have stickers!!

FullSizeRender (4)It’s a funny thing, but it seems laptop stickers are somehow pretty important to software developers… I know, because I am certainly guilty of plastering over several company laptops too – and I don’t want any sticker on my most important tool, I carefully apply only those with which I have a special interest or relation.

It is this realization that led Rebus.fm to order a bunch of Rebus stickers – so we can give them to people who like Rebus enough to want to show it to others.

Please get in touch if you want a sticker – then we’ll figure something out 🙂

 

ByMogens

Opening reception in The Alley

To mark the opening of Alley 87, we are having an opening reception on February the 12th at 14:00. Read More

ByMogens

Office in the alley

To improve focus – and to reduce the risk of me, ending up sitting at home in my underpants with a huge beard Read More

ByMogens

Rebus passed 300 stars on GitHub

I’m not sure this actually qualifies as “news”, but I still think it means something 🙂  Read More

ByMogens

It’s alive!

This is the first day of 2016, and Rebus Fleet Management a.k.a. rebus.fm is alive!

Read More