C# Code Snippets Func Action Lambda

C# Lambda Expressions

In this code snippet, we will take a look at lambda expressions, Func and Action in C#.Func is simply a more compact way of defining a delegate/function pointer while Action is the exact same thing as Func but for methods that return void. The lambda operator () => is a more compact way to define an anonymous method that can then be assigned to a delegate or passed into another method as a parameter. It’s very often combined with LINQ to form very concise queries that all fit into a single line of code.

C# Code Snippets Unsfe code Pointers Stackalloc and Spans

C# Unsafe code, Pointers, Stackalloc and Spans

In this code snippet, we will take a look at unsafe code, pointers, stack allocation and spans in C#. C# has managed memory unlike for example C/C++. This means that you don’t have to allocate or clear memory by yourself and in the case of .NET the CLR(common language runtime) takes care of memory allocation and garbage collection. This also means that in C# you can’t work with a pointer or allocate your variables on the stack which is common practice in C/C++.

C# Code Snippets LINQ Basics

C# LINQ Basics

In this code snippet, we will learn how to do some basic queries using LINQ(Language Integrated Query) in C#.LINQ is used to work with data within C# and can be used on enumerable types(IEnumerable or IQueryable interface) like lists, arrays, … A query can be made by using an SQL query like syntax or by method chaining. The latter is often combined with the lambda operator to specify some kind of condition as the parameter to the function/method.

mod schematic bottom

18650 Battery Charge Shield UPS Modification

In this post, I will show you how to modify the UPS so it works properly. Years ago I bought these 18650 battery charge shield boards that can be essentially used as a UPS(uninterruptible power supply). I just recently made a project that required a UPS so I finally decided to use them. This is when I found out about all the problems associated with this module.

Mini Portable Server From An Old Bitcoin Miner

Mini Portable Server From An Old Bitcoin Miner

In this post, I will document the build process for my mini portable server made from an old Bitcoin miner case and an Orange Pi Zero Plus. One day I was looking through my SBCs parts bin and saw the Orange Pi Zero Plus board(still in its packaging) I had bought many years ago but never used. I got the idea to make a small portable server that could maybe run an MQTT broker, act as an AP, run a web server, etc.

sonoff smart switch

Installing Tasmota On The Sonoff Smart Switch

In this post, I will show you how to flash a Sonoff Wi-Fi smart switch with the Tasmota firmware. Tasmoata is open source firmware for ESP chips. It gives you extra functionality like control via HTTP, Web UI, MQTT or serial compared to the Sonoff app. It also makes it easy to integrate with other services like Home Assistant. But most importantly it has no external dependencies and it won’t collect your data.