Skip to content

Instantly share code, notes, and snippets.

View linkdotnet's full-sized avatar

Steven Giesel linkdotnet

View GitHub Profile
@page "/{year:int}/{month:int}/{day:int}/{slug?}"
@using LinkDotNet.Blog.Domain
@using LinkDotNet.Blog.Infrastructure.Persistence
@inject IRepository<BlogPost> BlogPostRepository
@inject NavigationManager NavigationManager
@if(!noHit)
{
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
public class Benchmark
{
@linkdotnet
linkdotnet / BenchmarkDotnet7.cs
Last active April 20, 2022 19:16
Comparison of some scenarios between dotnet6 and dotnet7
/***************************************
* Benchmark Dotnet 7
*
* This file contains all the benchmarks running against dotnet6 and dotnet7
* As dotnet7 is currently in preview there is no "stable" support from BenchmarkDotNet
*
* To run those tests you have to add the nightly package which enables the dotnet7 support.
* More information can be found here: https://github.com/dotnet/BenchmarkDotNet/blob/master/docs/articles/guides/nuget.md
***************************************/
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
public class ListBenchmark
{
private List<int> numbers;
[Params(10, 100, 1_000, 10_000)]
public int ArraySize { get; set; }
using Bunit.Rendering;
namespace Bunit.Extensions.WaitForHelpers;
internal sealed class WaitForDisposedHelper : IDisposable
{
private const string TimeoutMessage = "The assertion did not pass within the timeout period.";
private const string ExceptionInPredicateMessage = "The state predicate throw an unhandled exception.";
private readonly IRenderedFragment renderedFragment;
@linkdotnet
linkdotnet / DebuggerAttributes.cs
Created February 10, 2022 12:49
DebuggerDisplay and DebuggerTypeProxy in Action
// See https://aka.ms/new-console-template for more information
using System.Diagnostics;
using System.Threading.Channels;
var father = new Person
{
Birthday = new DateTime(1970, 1, 1),
Name = "Father McFatherson",
};
using System;
public class Program
{
public static void Main()
{
Console.WriteLine($"Is 18 power of 3? {IsPowOf3(18)}"); // False
Console.WriteLine($"Is 81 power of 3? {IsPowOf3(81)}"); // True
Console.WriteLine($"Is 25 power of 5? {IsPowOf5(25)}"); // True
Console.WriteLine($"Is 725 power of 3? {IsPowOf3(725)}"); // False
@linkdotnet
linkdotnet / prepare-commit-msg
Created September 23, 2021 12:21
git hook for automatically prefix the ticket to your current
#!/bin/sh
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(main develop)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
TICKET_NAME=$(echo $BRANCH_NAME | grep -Poi '\w*/\K([0-9]+)')
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
ALREADY_IN_MSG=$(grep -ci "$TICKET_NAME" $1)
if [ -n "$BRANCH_NAME" ] && ! [[ "$BRANCH_EXCLUDED" -eq 1 ]] && ! [[ "$ALREADY_IN_MSG" -eq 1 ]]; then
@linkdotnet
linkdotnet / foreach_without_enumerable.cs
Created September 13, 2021 12:05
Foreach without enumerable
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var myList = new NotAList();
foreach (string item in myList)
@linkdotnet
linkdotnet / gist:df97d977319e281619c26563a1329c5a
Last active July 14, 2021 12:37
Benchmark string concat different approaches
using System;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace StringBuilderTest
{
class Program
{
static void Main(string[] args)