tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Simple caching interceptor (aspect) for Castle Windsor

23 Apr 2018 .NET, Aspect Oriented Programming (AOP), Caching, Castle Windsor, Inversion of Control (IoC)

I needed to cache value from method. Simple. I know there’s at least dozen of ready-made solutions, but I eventually decided to write my own interceptor, because the whole project is already using Castle Windsor and it seemed like a fun stuff to explore. There isn’t really anything special about this code and I originally didn’t want to blog about it, but people on Twitter changed my mind.

Fun with C#’s local functions – part 2

19 Apr 2018 C#

I was speaking about new features in C# 7.x and 8 some days ago and as the questions came in, some were really good small brainstorming, basically trying where C# compiler limits are. And that’s always interesting to me.

From this brainstorming I have two interesting pieces. This is the other one and the first one is here.

Fun with C#’s local functions – part 1

19 Apr 2018 C#

I was speaking about new features in C# 7.x and 8 some days ago and as the questions came in, some were really good small brainstorming, basically trying where C# compiler limits are. And that’s always interesting to me.

From this brainstorming I have two interesting pieces. This is the first one and the other one is here.

Global Azure Bootcamp 2018

11 Apr 2018 Azure, CDN, Presentations & Speaking

Global Azure Bootcamp 2018. Jeden den, Azure po celém světě. A taky v Čechách, v Praze. I já přispěju svojí troškou do mlýna a povím vám něco o Azure CDN v přednášce “Azure CDN a jak ji začít rozumně používat”.

Glowing filament of halogen bulb

4 Apr 2018 Electronics

I was testing dimmer during the weekend and I used halogen lamp in my garage. The dimmer worked great, but that’s not what I want to talk about now. When I played with the dimming I realized I can dim the 8000-9000 lumens halogen bulb down to one percent and see the glowing filament with my own eyes. So I did.

WUG Days 2018

30 Mar 2018 C#, Entity Framework Core, Presentations & Speaking, Programming in general

Víkend 7.-8.4. se v Brně koná nabitá konference WUG Days 2018. Celkem je připraveno 48 přednášek. Na dva dny masakr.

Hlasováním byly vybrány 3 moje přednášky. A sice:

WUG: C# 7, 7.1, 7.2 a 7.3/8.0 (Praha)

29 Mar 2018 C#, Presentations & Speaking

Máte rádi C#? A ztrácíte se v aktuální rychlé kadenci verzí? Mám pro vás řešení – WUG 5.4.2018 od 18:00 v Praze. Všechno dáme do kupy a srovnáme si to v hlavě.

C# v poslední době velmi rychle přidává nové funkce. Malé funkce v minor verzích, ale připravuji se i velké změny do major verze (verzí). Co je tedy dostupné v C# 7, 7.1, 7.2 a jak to začít používat. A co nás ceká v 7.3 a hlavně ve verzi 8.0?

Using value converter for custom encryption of field on Entity Framework Core 2.1

20 Mar 2018 Encryption, Entity Framework Core, Security

In February I wrote Custom encryption of field with Entity Framework Core post, which in turn was building on idea for Entity Framework 6. Both are easy, but not absolutely straightforward. And another problem is that the encrypted value needs to fit into the datatype of unencrypted value. Finally, the querying is inconvenient. Luckily Entity Framework Core 2.1 (currently in preview) has a solution.

True and false operators in C#

15 Mar 2018 C#

Few days ago, I learned new thing about C#. Apparently, there are “true” and “false” operators and you can overload these. But I also wanted to know what are these good for, given I’ve never heard about these.

Named locks (using Monitor) in .NET: Implementation

19 Feb 2018 .NET, Multithreading/Parallelism/Asynchronous/Concurrency

The Monitor class in .NET might be the most often used “locking” mechanism in C#, mostly because the lock keyword is making it so easy. One thing you might face is unknown number of locks you’re going to need and how to solve this. This is often called named locks or named Monitors, because the lock is bound to some name (or similar value).

How I got my machine back, patiently, after overloading it

7 Feb 2018 Disaster recovery, Lessons learned, Life, Operating systems, Windows

At the moment, one of my explorations is how the system (Windows) handles more-than-number-of-CPUs threads (all ready to run) under full load (from these threads). And because I’m out of office, I access my workstation remotely (using TeamViewer, in case you’re wondering).

Custom encryption of field with Entity Framework Core

5 Feb 2018 Encryption, Entity Framework Core, Security

Almost exactly 5 years ago (yes, that’s 2013) I wrote about Custom encryption of field with Entity Framework. At that time, it was using few tricks to make it work and although it might have looked like magic first time you saw it, it was actually very easy. With Entity Framework Core nowadays we have far more options how the entity can look like and hence how the whole solution can be plugged together. Let’s revisit the topic.

ShowIT 2018 a G2B•TechEd 2018

27 Jan 2018 Presentations & Speaking

Příští týden se konají po roce opět konference ShowIT (Bratislava) a G2B•TechEd (Brno) a myslím, že ještě nějaké místo urvat můžete. Aby se ani jedno město necítilo ochuzené, budu mít na stejné přednášky na obou. Povíme si něco o Azure CosmosDB.

Azure CosmosDB je databáze s globálním škálováním a dostupností. Podporuje několik modelů ukládání a konzistence. Má garantovanou dobu odezvy bez ohledu na data. A to vše jako služba v Azure. Wow! Je to opravdu tak přímočaré? Nebo je nadšení třeba krotit? Vysvětlím vám, jak CosmosDB funguje, na co se dá použít a uvidíme jestli je nadšení podloženo daty (třeba i těmi uvnitř DB 😉).

Tuples goodness in .NET 4.7.1 (.NET Core 2.0 included)

24 Jan 2018 .NET, .NET Core, .NET Standard, C#

One of the few things I was missing when tuples were introduced was some way to generically work with unknown tuples. Mostly to be able to identify tuples, instead of using plain object and also work with items using index of some sort. Luckily, I was probably not the only one and starting .NET 4.7.1 new interesting interface – ITuple – was added (also available in .NET Core 2.0).

About mentoring

26 Dec 2017 Career, Life, Programming in general

Recently in my social bubble, mostly on Twitter, there has been a lot of talking about mentoring. Senior developers mentoring juniors and so on. Although I’m not, by any means, saying mentoring is bad and juniors should leave seniors alone, I’d like to also share my opinion. Shedding some light into this seemingly black-and-white problem.

Entity Framework Core 2.0 provider for Firebird now in beta

11 Dec 2017 .NET, .NET Standard, C#, Databases in general, Entity Framework Core, Firebird, LINQ, SQL, Visual Studio

As I’m sweeping the corners, the work is less glamorous (read: close to zero outside contributions) and every move is harder and harder. But despite all of that, I’m glad to move one step closer to the RTM version of Entity Framework Core 2.0 provider for Firebird and jump to the beta phase.

WUG: Entity Framework Core 2.0 (Olomouc)

5 Dec 2017 Entity Framework, Presentations & Speaking

WUGy v Olomouci opět oživly a můžeme se tedy podívat společně na Entity Framework Core 2.0.

Entity Framework Core 2.0 byl představen nedávno společně s .NET Core 2 a ASP.NET Core 2. Co nového přináší? Jaké jsou změny oproti verzi 1.0 / 1.1? Má smysl verzi 2.0 používat? Jaké jsou pokročilejší features, jaká jsou její omezení… A co například použití s jinými databázemi než jen MS SQL Server?

Těším se na vás 12.12.2017 od 17:00 v Olomouci.

Changing paths in PDB files for source files (and PDB file path in DLL as well)

2 Dec 2017 .NET Core, Roslyn

Although you can disable PDB files generation altogether, it’s good idea to have these. Debugging without PDB files later is so much harder, like if debugging isn’t hard enough already. One thing that might be bothering you, is the source files location that is stored in PDB files. You might want to change these paths – build servers often use random directory names or you might want to simply hide that the project directory on your hard drive has some weird name. 😃

Are static methods faster in execution compared to instance methods (.NET)?

27 Nov 2017 .NET, .NET Core, JIT, RyuJIT

Couple days ago, fellow MVP and colleague @RobertHaken tweeted from frustration about a refactoring (in this case not a good refactoring) into static methods. And I immediately started thinking about scenario where the static method might have some tangible benefits compared to instance method. What a better way to improve method execution than speeding it up? Could this be the case?

Do not await what does not need to be awaited

17 Nov 2017 .NET, C#, Multithreading/Parallelism/Asynchronous/Concurrency

As the usage of await seeps more and more into general C# code, I’m finding some small “leaks” that make me sad sometimes. This one is pretty simple. Looks like that every time somebody uses XxxAsync method, he or she also awaits it. Makes sense, or does it?

Calibrating Aeotec Multisensor 6’s temperature using OpenZWave (in Domoticz)

6 Nov 2017 Domoticz, OpenZWave, Z-Wave

The Multisensor 6 from Aeotec is a nice little device. I have three of these in my house at the moment (and I’m sure I’m not done yet 😉). Being data geek I always calibrate the temperature (and humidity) sensor to match my own “calibration” devices (ESP-8266 with Si-7021). The steps described in official documentation are correct, but because I use OpenZWave (in Domoticz) I had to do some specific steps to make it work.

Using Azure CDN for complete static (running) website

20 Oct 2017 Azure, CDN, Cloud

If you read the documentation etc. for Azure CDN, it often expects that you’re going to use it on parts of your website and rest will be served directly from the original location. But if you have completely static (and currently running) website, like for example this blog, which is using the Azure CDN actually, you need to take a few specific steps to start using Azure CDN in such setup and without downtime.

JavaDays 2017

16 Oct 2017 Presentations & Speaking

Stejně jako .NET, Microsoft a techonologie kolem mají výbornou Gopas TechEd konferenci, má i Java svět svoji – JavaDays. Letos se uskuteční 13. – 14. listopadu a já jsem si připravil několik přednášek, které vás doufám zaujmou. Především kolem tématu databází, které je mi velmi blízké.

Playing with asyncio and aiohttp in Python as a C# developer

12 Oct 2017 Multithreading/Parallelism/Asynchronous/Concurrency, Python

Few months back I decided to play a little with asyncio in Python. Explore a little bit how “they did it” and align that in my mind with what I know about the implementation in .NET. Because at that time I needed some HTTP probing I decided to test the async IO together with regular HTTP (aka network) requests. And I used aiohttp. Not that I did some big research. I did quick search and looked at some demos to see whether I like how it’s structured or not. And aiohttp felt fine.

Comparing speed of “Count > 0” and “Any”

29 Sep 2017 .NET, C#, LINQ

I hate seeing Count > 0 when doing code reviews. And I always recommend using Any instead. It shows the intention, hence makes the code more readable, I think.

Although I would always choose readability over performance – unless in some very specific cases, with well-defined numbers – at one point I wondered whether there’s a cost in using Any. Speed? Allocations?

Konference CORESTART 2.0

20 Sep 2017 Presentations & Speaking

Letošní CORESTART 2.0 (2. – 3. listopadu) naváže na loňskou “edici”, tentokrát samozřejmě se zaměřením na .NET Core 2.0 a všeho okolo něj. Verze 2.0 už opravdu něco umí a jde na ní solidně stavět. Kromě zahraničních speakerů, přispěji i já svou troškou do mlýna dvěma přednáškami – jedna kolem Entity Frameworku Core 2.0 a druhá kolem novinek v C# 7 a dál. Novinek je hodně a program stojí za to. Přijďte, nebudete litovat.

Purple squiggle in Visual Studio

8 Sep 2017 Visual Studio

I’m pretty sure you know what the red squiggle in Visual Studio means (correct, it’s the error). Very likely you know green squiggle (correct, it’s the warning). Maybe you know blue squiggle (correct, it’s the message). But do you know what purple squiggle means? By the way the official name for squiggle in Visual Studio is wavy underline.

Run To Cursor in Call Stack window

7 Sep 2017 Visual Studio

Today I found a great new feature for debugging in Visual Studio. Maybe you know the Run to Cursor feature (if not, I’ll explain it in next paragraph), but did you know you can use the same feature from Call Stack as well?

My kind of Jekyll copy written in .NET

30 Aug 2017 .NET, C#, Hugo, Jekyll, Pelican, Ruby

Last couple of years I published this blog using Jekyll. Static pages are hard to beat in performance and security. Initially on GitHub pages, then GitLab Pages and eventually moving to Azure. Mainly because thanks to web.config I have more control over the webserver (IIS) and I can do bit more (in fact quite a lot). But lately I started to be more and more tired of Jekyll. It was slow for me and given it’s a Ruby application and me not being fan nor fluent of Ruby it started to add up. For maybe a year I looked multiple times at Hugo, because it was an obvious choice and didn’t liked the templating structure. Also Pelican, because it’s written in Python and I like Python. Not sure why, but I didn’t convert to it. And I also played multiple times with the idea of writing something myself, just to dismiss that idea hundred times because I knew I would trap myself in constantly fiddling with it and burning my free time.

ADO.NET provider for Firebird is ready (with .NET Standard 2.0 support)

30 Aug 2017 .NET, .NET Standard, C#, Databases in general, Entity Framework, Entity Framework Core, Entity SQL, Firebird, LINQ, SQL, Visual Studio

New version of ADO.NET provider for Firebird is ready for download. This release is about .NET Standard 2.0. Now the .NET Standard 2.0, with all the new APIs supported, version is available (this work, together with upcoming Entity Framework Core 2.0 support, is sponsored by Integrative9).

Another new feature is support for passing key over the wire for encrypted databases (you need to have server side plugin for this feature, i.e. this from IBPhoenix). New connection string property crypt key is available for that. The value is base64 encoded data representing the key. You can find small example in tests.

ADO.NET provider for Firebird is ready

25 Aug 2017 .NET, C#, Databases in general, Entity Framework, Entity SQL, Firebird, LINQ, SQL, Visual Studio

New version of ADO.NET provider for Firebird is ready for download. Apart from regular bugfixes some new features are available. Notably, FbTrace now supports new format of Firebird 3 and then DefaultFbMigrationSqlGeneratorBehavior allows easier customization in case you want specific behavior for Entity Framework Migrations.

Using string interpolation for ADO.NET parameters

16 Aug 2017 C#, SQL

I was reading the announcement about Entity Framework Core 2 the other morning and saw “String interpolation in raw SQL methods” paragraph. This was already in preview(s) and I kind of took it as granted, not thinking about how it’s done or what it is doing. Not this time. Somehow my curiosity kicked in and I decided to create same feature and maybe do something with it.

Of course, I could peek into sources, but I decided to use the idea, but build it myself from scratch. I like the idea of using already existing feature from C# and then using for different, but reasonable, purpose. String interpolation and SQL parameters are exactly this.

Replacing assembly while the application is running (aka AppDomains are slow)

25 Jul 2017 .NET, C#

As I said in previous post I had to drop AppDomains from my solution to allow replacing assembly while the FbNetExternalEngine is running. Calls across AppDomains are simply too slow (read: I can’t make it fast enough. 😉) for this kind of project. Why I even needed AppDomains? The specs are simple: Allow assembly replacing (rewrite) while it’s loaded in Firebird via my FbNetExternalEngine. Can it be solved without AppDomains?

FbNetExternalEngine performance numbers

24 Jul 2017 .NET, Firebird

Over the last few days I was working on performance of FbNetExternalEngine. Basically doing all I can to make it execute the code quickly as possible. OK, maybe not all I can, but something that gives biggest gain while being able to program it in a reasonable timeframe, because there’s always room for more.

Head- and Tail-like methods in C# (and F# and Python and Haskell)

27 Jun 2017 C#, F#, Functional programming, Haskell, Python

While writing previous post I realized the deconstruction to tuple can be added to any type. As far as compiler is concerned the Deconstruct method needs to exist, doesn’t matter whether it’s an extension method or instance one. That means I can write a Head- and Tail-like methods in C# with nice syntax. I also dusted off my Haskell knowledge and wrote the same logic there for comparison. And then I did it in Python and F# as well. Brace yourself for a true polyglot post.

Nice succinct syntax for tuple deconstruction

25 Jun 2017 C#

As I’m playing more and more with tuple in C# 7 to find out where this is useful and where it falls short and actually bites back later on. And during this I kind of by blind luck discovered more succinct syntax for deconstruction. I reminds me Python, which I like.

WUG: Nejčastější chyby při použití O/R mapperu (Zlín + Praha)

19 Jun 2017 Entity Framework, Presentations & Speaking

O/R mappery jsou výborný sluha, ale špatný pán. Abych tak trochu parafrázoval známé přísloví. David Gešvindr dobře zachytil, že v rámci různých Entity Framework přednášek apod. trousím, často i jako odpovědi na otázky z davu, různá doporcučení co nedělat (nebo co naopak dělat). Drobečky jsou fajn, ale dát to trochu do kupy a celkově sjednotit není od věci. A o tom je tato přednáška.

Example of optimizations “breaking” multithreaded code

11 Jun 2017 .NET, .NET Core, C#, Multithreading/Parallelism/Asynchronous/Concurrency

I realized I have some pieces of code to show some specific behavior, mostly around threading and synchronization, all over my notes. Some of these pieces may be 10+ years old. I use these pieces during my “threading/parallel/async” course, but why not to share it publicly. Maybe I’ll stumble on it after some years, maybe .NET will be history, and it will be interesting to re-read and re-think the code. The code isn’t unique or something where I’m the first to realize it. It’s really just an example code.

Today I have a small example that shows how optimizations (compiler, JIT, …) can make multithreaded code behave differently than expected. I don’t remember where I’ve seen the code. Some book or blog post from – I guess – Jeffrey Richter. Or maybe Joe Duffy or Stephen Toub or … These guys are very smart.

How much of objects sharing is there in LXSS?

2 Jun 2017 .NET Core, LXSS, Windows

I’m playing a little with Windows Subsystem for Linux (also known as WSL or LXSS), mostly to see what’s what and how it might be useful for my everyday usage. As I was reading some articles on how it’s implemented and how it works inside I’ve got an idea. What if I create an application, in .NET Core, that uses some resource from kernel and I execute it both regular Windows session and in LXSS, will this resource be shared across?