Skip to content

Instantly share code, notes, and snippets.

View otto-gebb's full-sized avatar

otto-gebb

  • Karlsruhe
View GitHub Profile
# winget install JanDeDobbeleer.OhMyPosh -s winget
# https://ohmyposh.dev/docs/installation/customize
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/unicorn.omp.json" | Invoke-Expression
# Install-Module -Name PSFzf
# https://github.com/kelleyma49/PSFzf/tree/master?tab=readme-ov-file#psfzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
# choco install zoxide -y
Invoke-Expression (& { (zoxide init powershell | Out-String) })
using System.Threading.Channels;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
builder.Services.AddSingleton<SettingsQueue>();
var host = builder.Build();
var writer = host.Services.GetRequiredService<SettingsQueue>().Settings.Writer;
writer.TryWrite(true);
/*
When `LogOperation1` logs the exception, the log record does not contain the properties
of the logging scope that were active at the moment of throwing.
`LogOperation2` has no such issue.
Demo:
dotnet run | grep '^{' | jq 'del(.["@t"], .["@i"], .["@l"], .["@x"], .SourceContext)'
{
"@m": "Starting operation: \"Fail1\"",
"OperationName": "Fail1"
}
#!/usr/bin/env bash
whoami
let inline fromStr< ^T when ^T : enum<int32> and ^T : equality >(s: string) : Option< ^T > =
let t = typeof<'T>
let enumStrings = System.Enum.GetNames(t)
let vals = System.Enum.GetValues(t) :?> 'T[]
Array.zip vals enumStrings
|> Array.tryFind (fun (x, s') -> s' = s)
|> Option.map fst
let inline toStr< ^T when ^T : enum<int32> and ^T : equality >(x: ^T) =
let t = typeof<'T>
@otto-gebb
otto-gebb / reverseParentheses.fsx
Last active January 5, 2019 06:52
ReverseParentheses - Codefights
(*
You are given a string s that consists of English letters, punctuation marks,
whitespace characters and brackets.
It is guaranteed that the brackets in s form a regular bracket sequence.
Your task is to reverse the strings in each pair of matching parenthesis,
starting from the innermost one.
Example
For string "s = a(bc)de" the output should be
#pragma warning disable 1591
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using DomainDbHelpers.Domain;
using DomainDbHelpers.DomainHelpers;
using DomainDbHelpers.Persistence;
using DomainDbHelpers.PersistenceHelpers;
namespace TestUtils
/// An unbounded pool of browsers.
module BrowserPool =
open System
open OpenQA.Selenium.Chrome
open System.Collections.Concurrent
let private pool = ConcurrentQueue<ChromeDriver>()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
// A separate NuGet package.
namespace Acme.Validation
{
public static class Validator
{
<#
.NOTES
Licensed under WTFPL, Version 2.
.SYNOPSIS
Extracts the DB-schema from the latest EF migration in the specified database.
.DESCRIPTION
Writes the extracted schema to the output file in the EDMX format.
The "(local)" server is used.
.PARAMETER Database
The database with EF migrations (in the __MigrationHistory table).