Skip to content

Instantly share code, notes, and snippets.

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

Damian Edwards DamianEdwards

🏠
Working from home
View GitHub Profile
// Now
app.MapGet("/todos/{id}", async (int id, TodoDb db) =>
await db.Todos.FindAsync(id)
is Todo todo
? Results.Ok(todo)
: Results.NotFound())
.WithName("GetTodoById")
.Produces<Todo>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound);
@DamianEdwards
DamianEdwards / Program.cs
Last active February 16, 2022 01:43
Potential ASP.NET Core Minimal APIs use of C# Discriminated Unions (DU)
// Ref: https://github.com/cston/csharplang/blob/DiscriminatedUnions/proposals/tagged-unions.md
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using MiniValidation;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("TodoDb") ?? "Data Source=todos.db";
builder.Services.AddSqlite<TodoDb>(connectionString);
@DamianEdwards
DamianEdwards / Microsoft.PowerShell_profile.ps1
Last active August 24, 2023 17:27
PowerShell Profile & oh-my-posh theme
function Get-ProgramFiles32() {
if (${env:ProgramFiles(x86)} -ne $null) {
return ${env:ProgramFiles(x86)}
}
return $env:ProgramFiles
}
function Get-VsInstallLocation() {
$programFiles = Get-ProgramFiles32
$vswhere = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
@DamianEdwards
DamianEdwards / craver-vs.omp.json
Last active July 13, 2023 00:23
My oh-my-posh profile
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "#f1184c",
"properties": {
"template": " \uf0e7 "
@DamianEdwards
DamianEdwards / vs.omp.json
Last active October 6, 2021 19:33
Trying to make an oh-my-posh text segment that hides itself when there's no value
{
"type": "text", // VS version
"style": "powerline",
"powerline_symbol": "\uE0C4",
"foreground": "#ffffff",
"background": "#5C2D91", // VS purple from https://visualstudio.microsoft.com/
"properties": {
"prefix": "",
"text": "{{if .Env.VSCMD_VER}} ﬏ {{.Env.VSCMD_VER}} {{end}}",
"postfix": ""
@DamianEdwards
DamianEdwards / ShutdownHostingStartup.cs
Created March 15, 2021 23:13
ASP.NET Core IHostingStartup that as soon as the site has started makes a request to itself then shuts itself down
using System;
using System.Linq;
using System.Net.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@DamianEdwards
DamianEdwards / server.cs
Created February 25, 2021 01:31
Simplified ASP.NET Core app exploration
#!/usr/bin/env dotnet run
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
var connString = config["connectionString"] ?? "Data Source=todos.db";
builder.AddDbContext<TodoDb>(options => options.UseSqlite(connString));
builder.AddSqlite<Todo>(connString) // Higher level API perhaps?
var app = builder.Build();
2020-03-28 17:23:24,672 WARN 1 OutlookGoogleCalendarSync.OutlookOgcs.Calendar [0] - Sorry, something went wrong. You may want to try again.
2020-03-28 17:24:27,598 WARN 1 OutlookGoogleCalendarSync.Sync.PushSyncTimer [0] - Push Sync failed 3277 times to check for changed items.
2020-03-28 17:24:27,600 ERROR 1 OutlookGoogleCalendarSync.OGCSexception [0] - System.Runtime.InteropServices.COMException: Sorry, something went wrong. You may want to try again.
2020-03-28 17:24:27,601 ERROR 1 OutlookGoogleCalendarSync.OGCSexception [0] - Code: 0x85270057;-2061041577
2020-03-28 17:24:55,940 WARN 1 OutlookGoogleCalendarSync.OutlookOgcs.Calendar [0] - Sorry, something went wrong. You may want to try again.
2020-03-28 17:24:59,851 WARN 1 OutlookGoogleCalendarSync.Sync.PushSyncTimer [0] - Push Sync failed 3278 times to check for changed items.
2020-03-28 17:24:59,851 ERROR 1 OutlookGoogleCalendarSync.OGCSexception [0] - System.Runtime.InteropServices.COMException: Sorry, something went wrong. You may want to
@DamianEdwards
DamianEdwards / certs.ps1
Last active March 27, 2020 23:40
Self-signed certificate experiments
# Generate root cert
$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature `
-Subject "CN=AspNetCoreCertAuthRoot" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign
# Make sure to trust this root cert
# Generate child cert with Client Authentication OID
New-SelfSignedCertificate -Type Custom -DnsName P2SChildCert -KeySpec Signature `
@DamianEdwards
DamianEdwards / azure-pipelines.yaml
Created March 25, 2020 23:21
.NET Core Azure stuff
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
branches:
include:
- master
paths: