Skip to content

Instantly share code, notes, and snippets.

View joacar's full-sized avatar

Joakim Lindh joacar

View GitHub Profile
@joacar
joacar / openid-jwks.ps1
Created September 28, 2021 09:40
Create certificates from OpenID well known configurations meta data by following the 'jwks_uri' and iterate the keys result.
Param(
[Parameter(Mandatory = $True, Position=1)][string]$BaseUrl
)
function Get-Json {
Param([string]$json, [string]$key)
ConvertFrom-Json $json | Select-Object -expand $key
}
$configuration = Invoke-WebRequest -ContentType "application/json" -Uri "$BaseUrl/.well-known/openid-configuration"
@joacar
joacar / cer2crt.sh
Created October 2, 2020 12:08
Working with certificates and openssl
#!/bin/bash
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
joacar / Program.cs
Last active August 20, 2020 09:43
XML generation in various ways. Trying to get just an XmlElement class to assign a property in a class generated from XSD
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleAppXml
{
internal class Program
{
@joacar
joacar / NServiceBusEventDispathing.cs
Last active October 15, 2019 13:23
NServiceBus shared service provider attempt
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
joacar / MicrosoftLoggerEventIdProvider.cs
Last active April 3, 2019 08:27
EventId provider to retrieve event id from log calls made by `Microsoft.Extensions.Logging` and write to Windows Event Log
/// <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
joacar / SqlBuildScripts.ps1
Last active October 19, 2018 13:56
Scripts for building database project in Visual Studio and generate DacPac to create update scripts
# "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 https://github.com/psake/psake
<#
.SYNOPSIS
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
joacar / Add-Migration.bat
Last active June 28, 2018 17:14
dotnet ef command line helper files
@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
joacar / PartialSetSlicer.cs
Created June 20, 2018 08:05
Accomodate for missing values when rendering a portion of a data set with e.g. Google Pie Chart
/// <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
joacar / Program.cs
Last active June 5, 2018 11:27
Operation MediatR pipeline
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
namespace TestingMediatR
{
/// <summary>
@joacar
joacar / deploy.sh
Last active February 23, 2018 09:44
Script to copy content from VSTS Agent release artificat to web folder
#!/bin/bash
dir=/var/<app>
src=/home/user/vstsagent/_work/r1/a/<app>/drop/<app>.zip
service=<app>.service
# Clear directory
echo "Remove content from '$dir'"
rm -r $dir >> /dev/null