Skip to content

Instantly share code, notes, and snippets.


Joakim Lindh joacar

View GitHub Profile
joacar /
Created Oct 2, 2020
Working with certificates and openssl
usage() {
echo "Usage: $0"
echo " <file>.cer - Windows certificate file .cer format."
echo " <file> - File name generated .crt. Default to <file>.crt."
exit 1
if [ -z "$1" ]; then
joacar / Program.cs
Last active Aug 20, 2020
XML generation in various ways. Trying to get just an XmlElement class to assign a property in a class generated from XSD
View Program.cs
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleAppXml
internal class Program
joacar / NServiceBusEventDispathing.cs
Last active Oct 15, 2019
NServiceBus shared service provider attempt
View NServiceBusEventDispathing.cs
namespace Nordax.NServiceBus {
/// <summary>
/// Behavior that wraps invocation of pipeline with a scoped service provider.
/// </summary>
internal sealed class ScopedServiceBehavior : Behavior<IIncomingPhysicalMessageContext>
/// <summary>
/// Registered behavior with name.
/// </summary>
public const string StepId = "ScopedService";
joacar / MicrosoftLoggerEventIdProvider.cs
Last active Apr 3, 2019
EventId provider to retrieve event id from log calls made by `Microsoft.Extensions.Logging` and write to Windows Event Log
View MicrosoftLoggerEventIdProvider.cs
/// <inheritdoc />
/// <summary>
/// Extract the EventId.Id value from <see cref="Microsoft.Extensions.Logging.EventId" /> passed with
/// <see cref="Microsoft.Extensions.Logging" /> and set the <c>Event ID</c> field in Windows Event Log.
/// </summary>
/// <remarks>
/// <para>
/// Serilog creates an <see cref="Serilog.Events.LogEventPropertyValue" /> with two
/// <see cref="Serilog.Events.ScalarValue" /> combined into
/// <see cref="Serilog.Events.StructureValue" />. One <c>ScalarValue</c> has the actual id with the key <c>Id</c> and the
joacar / SqlBuildScripts.ps1
Last active Oct 19, 2018
Scripts for building database project in Visual Studio and generate DacPac to create update scripts
View SqlBuildScripts.ps1
# "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
# "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\"
# Taken from psake
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
joacar / Add-Migration.bat
Last active Jun 28, 2018
dotnet ef command line helper files
View Add-Migration.bat
@echo off
if "%~1"=="" (
set /p "migration=Migration name is required. Enter name: "
if "%migration%"=="" ( exit /b )
set "filepath=%~2"
REM Content file is just one line as "-c MyDdContext -p Path/To/Project.csproj -o Path/To/Migrations
joacar / PartialSetSlicer.cs
Created Jun 20, 2018
Accomodate for missing values when rendering a portion of a data set with e.g. Google Pie Chart
View PartialSetSlicer.cs
/// <summary>
/// Model to work with a subset of a set and render charts and graphs correctly.
/// </summary>
public class PartialSetSlicer
/// <summary>
/// Construct a <see cref="PartialSetSlicer" /> with <see cref="Threshold" /> set to the distribution of the last element.
/// </summary>
/// <param name="set">Data set.</param>
/// <param name="size">Size for subset.</param>
joacar / Program.cs
Last active Jun 5, 2018
Operation MediatR pipeline
View Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
namespace TestingMediatR
/// <summary>
joacar /
Last active Feb 23, 2018
Script to copy content from VSTS Agent release artificat to web folder
# Clear directory
echo "Remove content from '$dir'"
rm -r $dir >> /dev/null
joacar / t-sql.sql
Created Feb 22, 2018
Import data into SQL from Google Spreadsheet or Microsoft Excel
View t-sql.sql
-- Split string Table-Valued function
@Character CHAR(1)
Item NVARCHAR(1000)