Skip to content

Instantly share code, notes, and snippets.

bitbonk bitbonk

Block or report user

Report or block bitbonk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bitbonk
bitbonk / config.md
Last active Nov 11, 2019
Example Serilog Config with C# and JSON
View config.md

C# config:

var logConfig = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .Enrich.FromLogContext()
    .WriteTo.ColoredConsole(LogEventLevel.Error, "{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3} {SourceContext}: {Message}{NewLine}")
    .WriteTo.Logger(
        c => c.WriteTo.ColoredConsole(LogEventLevel.Information, "{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3} {SourceContext}: {Message}{NewLine}")
            .Filter.ByIncludingOnly("SourceContext = 'Microsoft.Hosting.Lifetime'"))
View GenericHostWithWpfAndCaliburn.cs
public class MyCaliburnBootstrapper : BootstrapperBase
{
private IHost? host;
protected MyCaliburnBootstrapper()
{
this.Initialize();
}
private IHost BuildHost()
View 1. MainWindow.cs
private Task completion = Task.CompletedTask;
private int counter;
private async void ButtonOnClick(object sender, RoutedEventArgs e)
{
this.completion = this.completion.ContinueWith(async _ =>
{
this.counter = this.counter + 1;
Debug.WriteLine($"Enter ButtonOnClick {counter}");
await DoSubAsync(counter);
View 1. MainWindow.cs
private Task completion = Task.CompletedTask;
private int counter;
private void ButtonOnClick(object sender, RoutedEventArgs e)
{
this.completion = this.completion.ContinueWith(async _ =>
{
this.counter = this.counter + 1;
Debug.WriteLine($"Enter ButtonOnClick {counter}");
await DoSubAsync(counter);
View 1. MainWindow.cs
private int counter = 0;
private async void ButtonOnClick(object sender, RoutedEventArgs e)
{
counter = counter + 1;
Debug.WriteLine($"Enter ButtonOnClick {counter}");
await DoSubAsync(counter);
Debug.WriteLine($"Exit ButtonOnClick {counter}");
}
public async Task DoSubAsync(int number)
{
@bitbonk
bitbonk / Program.cs
Last active Feb 8, 2019
System.Threading.Channels (C# 8)
View Program.cs
namespace ChannelTest
{
using System;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
class Program
{
public static async Task Main(string[] args)
@bitbonk
bitbonk / NETClassic.json
Last active Jan 21, 2019
JSON Deserailization .NET Core vs. .NET Classic
View NETClassic.json
{
"$type": "MyNamespace.Dto`6[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], NETClassicApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"StringProp": "my string",
"DoubleProp": 123.0,
"FloatProp": 345.0,
"ByteArrayProp": {
"$type": "System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$value": "AQID"
},
"UriProp": "http://localhost:80",
@bitbonk
bitbonk / Program.cs
Created Jan 19, 2019
Hello World System.Threading.Channels
View Program.cs
using System;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
class Program
{
public static async Task Main(string[] args)
{
var channel =
@bitbonk
bitbonk / Clients.cs
Created Nov 6, 2018
very simple signalr server + client
View Clients.cs
class Program
{
static async Task Main(string[] args)
{
var connection = new HubConnectionBuilder().WithUrl("http://localhost:19715/chat")
.Build();
await connection.StartAsync();
var receiveCounter = 0;
var isReceiver = args.Length < 1 || args[0].ToLower() != "sender";
@bitbonk
bitbonk / deploy.ps1
Created Jan 10, 2017
deploy something but exclude some stuff
View deploy.ps1
<#
.SYNOPSIS
Copies the files that belong to a deployment to a target folder.
.PARAMETER Source
The path of the source folder.
.PARAMETER Target
The path of the target folder.
#>
[CmdletBinding(SupportsShouldProcess=$True)]
You can’t perform that action at this time.