Skip to content

Instantly share code, notes, and snippets.

View haacked's full-sized avatar
🏠
Code code code

Phil Haack haacked

🏠
Code code code
View GitHub Profile
@haacked
haacked / serious-startup-resources.md
Last active October 28, 2022 00:17
Resources from Serious Lessons Building a Startup with Azure and ASP.NET Core
  1. Abbot - The product my company is building and subject of the talk.
  2. A Serious Business, Inc. - My company.
  3. Age and High-Growth Entrepreneurship - Contains the graph of the probability of successful exit by age.
  4. Hubot - our old friend and inspiration for Abbot.
  5. Chat-Ops - the way of working together in Chat with a bot.
  6. YCombinator - The Startup Incubator we joined.
  7. ASP.NET Core - A big part of our tech stack
  8. PROJECT MANAGEMENT - A TREE SWING STORY - source of the tree-swing cartoon which originally started in the 70s
  9. [Making sense of MVP](https://blog.crisp.se/2016/01/25/henrikkn
@haacked
haacked / stripe-mrr.cs
Last active November 8, 2022 12:54
Calculating MRR with C# and the Stripe API
// This is the source for the blog post here: https://haacked.com/archive/2022/10/12/calculating-mrr-with-stripe-and-csharp/
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace Stripe;
public static class StripeExtensions
@haacked
haacked / upcast-example.cs
Last active April 21, 2022 20:05
Upcast record without more specific type properties
// Suppose we have the two record types
public record Person(int Id) : PersonUpdate()
{
};
public record PersonUpdate()
{
public string Name {get; init;}
//... bunch of other properties.
@haacked
haacked / never-not.cs
Last active March 23, 2021 21:40
Weird roslyn waring
public interface IArgument
{
/// <summary>
/// The value of the argument sans quotes.
/// </summary>
string Value { get; }
}
public interface IArguments : IReadOnlyList<IArgument>, IArgument
{
@haacked
haacked / ForbiddenTypeAnalyzer.cs
Last active May 14, 2023 18:38
Roslyn Analyzer to warn about access to forbidden types
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
// CREDIT: https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/Core/SymbolIsBannedAnalyzer.cs
[DiagnosticAnalyzer(LanguageNames.CSharp)]
@haacked
haacked / jsonconvert-bug.cs
Created June 8, 2020 00:00
JsonConvert Bug?
[Fact]
public void StackTest()
{
var stack = new Stack<string>();
stack.Push("one");
stack.Push("two");
stack.Push("three");
var serialized = JsonConvert.SerializeObject(stack, new JsonSerializerSettings
{
@haacked
haacked / LayoutForPartialTagHelperExample.md
Last active April 1, 2020 18:18
I would like a way to do this with the partial tag helper.

What I'm looking for is a nicer more declarative approach to Templated Razor Delegates

In Any old Razor Page or View - SomePage.cshtml

...
<div>
  <partial name="Shared/_PartialLayout" for="SomeModel">
    <strong>Content</strong> that will be injected into the layout, which 
 will get rendered here.
@haacked
haacked / RoleProfileService.cs
Last active September 18, 2019 15:25
Providing Role Claims
/*
This needs to be registered with the IdentityServer in the Startup.cs
by calling AddProfileService<RoleProfileService>() on the builder returned
by AddIdentityServer.
ex...
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
@haacked
haacked / ModelBuilderExtensions.cs
Last active March 29, 2024 14:16
Example of applying an EF Core global query filter on all entity types that implement an interface
/*
Copyright Phil Haack
Licensed under the MIT license - https://github.com/haacked/CodeHaacks/blob/main/LICENSE.
*/
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
@haacked
haacked / index.js
Created February 9, 2019 20:49
Probot handler for the Why Not Both app
module.exports = (app) => {
// Respond to new issue comments
app.on('issue_comment.created', async context => {
const message = context.payload.comment.body
// The following does a rough approximation of
// trying to find a question that proposes two
// alternatives. It's not very smart about it,
// but good enough for our case.
const dichotomy = message.toLowerCase()