Skip to content

Instantly share code, notes, and snippets.

View doeringp's full-sized avatar
🏠
Working from home

Peter Doering doeringp

🏠
Working from home
View GitHub Profile
@doeringp
doeringp / findCssClass.js
Last active June 21, 2023 09:43
Find a css class that is available on a web page
const findCssClass = (name) =>
Array.from(document.querySelectorAll("[class]"))
.flatMap(e => Array.from(e.classList))
.filter(s => s.indexOf(name) > -1)
findCssClass("text")
// => ['text-center', 'text-xl', '!text-sm', 'text-xl', 'text-center', 'text-center']
@doeringp
doeringp / AsyncExtensions.cs
Created March 29, 2023 10:37
Extends Task.WhenAny to return only a task if a condition matches
public static class AsyncExtensions
{
/// <summary>
/// Creates a task that will complete when any of the tasks have completed and the task result matches the <paramref name="condition"/>.
/// </summary>
/// <typeparam name="TResult">The result type produced by each task in the list.</typeparam>
/// <param name="tasks">The tasks to wait on for completion.</param>
/// <param name="condition">The condition the completed task should match in order to be returned.</param>
/// <returns>
/// A task that represents the completion of one of the supplied tasks.
@doeringp
doeringp / sqlserver-list-locks.sql
Created October 21, 2022 09:57
SQL Server: List all Locks of the Current Database
SELECT TL.resource_type AS ResType
,TL.resource_description AS ResDescr
,TL.request_mode AS ReqMode
,TL.request_type AS ReqType
,TL.request_status AS ReqStatus
,TL.request_owner_type AS ReqOwnerType
,TAT.[name] AS TransName
,TAT.transaction_begin_time AS TransBegin
,DATEDIFF(ss, TAT.transaction_begin_time, GETDATE()) AS TransDura
,ES.session_id AS S_Id
@doeringp
doeringp / sqlserver-cursor-based-pagination.sql
Created June 17, 2022 10:30
Cursor-based pagination for SQL Server
-- The ID value of the last row from the previous page.
DECLARE @Cursor NVARCHAR(100) = '19';
-- The number of rows you want for the next page.
DECLARE @PageSize INT = 10;
WITH [Query] AS (
SELECT * FROM dbo.ProductModel
)
SELECT * FROM [Query]
@doeringp
doeringp / README.md
Last active June 17, 2022 10:41
Data replication between databases on the same server using triggers (for SQL Server)

Data replication between databases on the same server using triggers (for SQL Server)

This sample shows how to replicate data between two tables in different databases on the same server. I was looking for the most simple pragmatic approach I could think of. Please be aware that triggers have some disadvantages. Please think carefully before following the approach.

How it works

  • If you insert a row in the table in database A
  • a trigger will execute automatically
@doeringp
doeringp / AspNetCoreFeatureFlagsSpaSample.csproj
Last active March 20, 2023 22:37
ASP.NET Core Feature Flags for SPAs
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="2.4.0" />
<PackageReference Include="System.Linq.Async" Version="5.1.0" />
</ItemGroup>
@doeringp
doeringp / Program.cs
Created May 17, 2021 07:07
Samples for structured logging in .NET 5.0
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(whb => whb.Configure(app =>
{
var logger = app.ApplicationServices.GetRequiredService<ILogger<Foo>>();
@doeringp
doeringp / replaceBaseHref.js
Created March 1, 2021 05:22
Replaces the value of the <base href="..."> in a HTML document.
const fs = require('fs')
const args = process.argv.slice(2);
if (args.length < 2)
{
console.log(`Replaces the value of the <base href="..."> in a HTML document.
USAGE:
node replaceBaseHref.js <html-file> <new-value> [encoding]
@doeringp
doeringp / _powershell-profile.ps1
Last active October 8, 2021 08:34
My PowerShell Profile (see $PROFILE)
# Oh my Posh is a great tool to make a pretty prompt in your PowerShell.
# See https://ohmyposh.dev/docs/windows
Import-Module posh-git
# My personal oh my posh theme
oh-my-posh --init --shell pwsh --config ~\AppData\Local\Programs\oh-my-posh\themes\pietdoe.omp.json | Invoke-Expression
# Aliases for "docker" and "docker-compose" commands to use Podman under WSL2 instead.
Function docker { wsl sudo podman $args }
Function podman-api { wsl sudo podman --log-level=debug system service -t0 unix:///var/run/docker.sock }
Function docker-compose { wsl sudo docker-compose $args }
@doeringp
doeringp / authorize.service.ts
Last active September 16, 2020 13:58
Sample AuthorizeService (wrapper for oidc-client.js) of Microsoft from the ASP.NET Core 3.1 Angular template #Angular #OpenIDConnect
import { Injectable } from '@angular/core';
import { User, UserManager, WebStorageStateStore } from 'oidc-client';
import { BehaviorSubject, concat, from, Observable } from 'rxjs';
import { filter, map, mergeMap, take, tap } from 'rxjs/operators';
import { ApplicationPaths, ApplicationName } from './api-authorization.constants';
export type IAuthenticationResult =
SuccessAuthenticationResult |
FailureAuthenticationResult |
RedirectAuthenticationResult;