Skip to content

Instantly share code, notes, and snippets.

@slovely
slovely / AppHost.cs
Last active May 20, 2025 15:29
Aspire
// in the app host:
// Has a database that I can reference with EF no issue
var db = builder.AddPostgres("db").AddDatabase("db");
// Custom dockerfile which has an app running on container port 8080
var svc = builder.AddDockerfile( "svc", "./", "./Dockerfile")
.WithEndpoint(0, 8080, "http", "http")
;
@slovely
slovely / Extensions.cs
Created April 2, 2025 17:12
Decorator pattern using crappy .NET container only
public static class DecoratorRegistrationExtensions
{
/// <summary>
/// Registers a <typeparamref name="TService"/> decorator on top of the previous registration of that type.
/// </summary>
/// <param name="decoratorFactory">Constructs a new instance based on the the instance to decorate and the <see cref="IServiceProvider"/>.</param>
/// <param name="lifetime">If no lifetime is provided, the lifetime of the previous registration is used.</param>
public static IServiceCollection AddDecorator<TService>(
this IServiceCollection services,
Func<IServiceProvider, TService, TService> decoratorFactory,
@slovely
slovely / HomeAssistant.md
Last active September 27, 2024 12:45
Updating home assistant to postgres
  1. BACKUP YOUR HOME ASSISTANT!
  2. Grab the SQLite database somewhere
  3. Install pgloader ** Create postgres database:
create database ha_live;

CREATE USER ha_live WITH ENCRYPTED PASSWORD '<password>';
GRANT ALL PRIVILEGES ON DATABASE ha_live TO ha_live;
GRANT ALL  ON DATABASE ha_live TO ha_live;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using Marten;
using Marten.Events.Projections;
using Xunit;
using Xunit.Abstractions;
@slovely
slovely / Program.cs
Last active June 21, 2020 10:43
EF Core StackOverflowException
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
namespace StackOverflowTest
{
public class Program
{
public static string ConnectionString =
@slovely
slovely / TypeScript-Generation.ts
Created March 7, 2017 15:08
Generated WebAPI actions
// Assume a WebAPI action on the server
// [HttpPost]
// public SomeType TheAction(string s, AnotherType obj) {
// return new SomeType(s.Length, obj.name);
// }
// Where SomeType is
// public class SomeType{ public int Property1{get;set;} public string Property2{get;set;}}
// and AnotherType is
// public class AnotherType {public string Name{get;set;}}
@slovely
slovely / maps.js
Created January 27, 2016 22:13
OverlappingFeatureSpiderfier.js example
<html>
<head>
<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
#map { height: 100%; }
</style>
</head>
<body>
@slovely
slovely / program.cs
Created October 30, 2014 22:15
Sample console app for generating TypeScript models
using System;
using System.IO;
using System.Reflection;
using TypeLite;
namespace TypeScriptSample.Generator
{
class Program
{
static void Main(string[] args)
@slovely
slovely / generated.ts
Created October 28, 2014 22:17
Complete output from TypeLite fork
declare module TypeLite.Tests.GenericsTests {
interface ClassWithComplexNestedGenericProperty {
GenericsHell: System.Tuple<System.Collections.Generic.KeyValuePair<number, string>, TypeLite.Tests.GenericsTests.BaseGeneric<string>, number, System.Collections.Generic.KeyValuePair<number, DummyNamespace.Test>>;
}
interface BaseGeneric<TType> {
SomeGenericProperty: TType;
SomeGenericArrayProperty: TType[];
}
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace ConsoleApplication1
{
[TestClass]
public class CustomMoq
{
public class Message
{