Skip to content

Instantly share code, notes, and snippets.

View Bio2hazard's full-sized avatar

Felix Kastner Bio2hazard

View GitHub Profile
void Main()
{
var fileInfoOriginal = new FileInfo(@"C:\Development\project-dev-12345-67890-abcdefg.tar.gz"); // unmodified
var fileInfoModified = new FileInfo(@"C:\Development\project-dev-12345-67890-abcdefg-modified.tar.gz"); // modified
using var fileStreamOriginal = fileInfoOriginal.OpenRead();
using var decompresssionStreamOriginal = new GZipStream(fileStreamOriginal, CompressionMode.Decompress);
var original = InspectTarHeader(decompresssionStreamOriginal);
using var fileStreamModified = fileInfoModified.OpenRead();
@Bio2hazard
Bio2hazard / Dockerfile
Last active September 17, 2021 21:52
Dotnet 6 GC Server OOM Reproduction.
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:6.0.0-rc.1-bullseye-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0.100-rc.1-bullseye-slim AS build
WORKDIR /src
COPY ["memoryrepro.csproj", ""]
RUN dotnet restore "./memoryrepro.csproj"
COPY . .
@Bio2hazard
Bio2hazard / Dockerfile39
Created October 20, 2019 03:41
Dotnet core 2.2.7 on Alpine 3.9 Memory Leak reproduction
FROM mcr.microsoft.com/dotnet/core/sdk:2.2.402-alpine3.9 AS build
ADD . /opt/testapp
WORKDIR /opt/testapp
RUN dotnet restore && \
dotnet publish -c Release -o dist
FROM mcr.microsoft.com/dotnet/core/runtime:2.2.7-alpine3.9 as runtime
COPY --from=build /opt/testapp/dist /opt/testapp/dist
ENV ASPNETCORE_ENVIRONMENT=Production
WORKDIR /opt/testapp/dist
@Bio2hazard
Bio2hazard / FastStringBuilder.cs
Created April 11, 2019 00:31
An attempt to make allocation-free string fragment concatenation
public ref struct FastStringBuilder
{
private int _pos;
private int _totalLength;
private readonly ReadOnlyMemory<char>[] _mems;
public FastStringBuilder(int maxPieces)
{
_pos = 0;
_totalLength = 0;
@Bio2hazard
Bio2hazard / Program.cs
Created March 23, 2019 08:21
Cloudwatch Lister
using System;
using System.Threading.Tasks;
using Amazon;
using Amazon.CloudWatchLogs;
using Amazon.Extensions.NETCore.Setup;
namespace Test
{
class Program
{
@Bio2hazard
Bio2hazard / FunctionBase.cs
Created July 14, 2017 22:48
CTOR DI In Azure Webjobs
using System;
using System.Threading.Tasks;
using SimpleInjector;
namespace Your.Namespace
{
/// <summary>
/// Provides an abstraction for WebJob functions, enabling dependency injection.
/// Mandatory to have on all triggered functions for proper disposal of execution scope.
/// </summary>
@Bio2hazard
Bio2hazard / BAREBONES_RaygunExceptionHandler.cs
Last active March 3, 2017 21:00
Raygun integration for webjobs
public static class RaygunExceptionHandler
{
private static readonly RaygunClient _client;
static RaygunExceptionHandler()
{
_client = new RaygunClient("your_apikey");
_client.AddWrapperExceptions(typeof(FunctionInvocationException));
}
@Bio2hazard
Bio2hazard / Example Migration.sql
Last active August 27, 2022 17:26
Visual Studio Database Project Migrations Help Scripts
If dbo.fnTableExists('Rewards') = 1 AND dbo.fnColumnExists('Rewards', 'Completed') = 1
Begin
PRINT N'Rewards exists and Completed column exists. Removing column.';
ALTER TABLE [dbo].[Rewards] DROP COLUMN [Completed];
PRINT N'Completed column has been removed.';
End
@Bio2hazard
Bio2hazard / composition_concrete.cs
Created February 18, 2016 00:32
Composition? Inheritance? Best approach?
/*
Pro:
- Least amount of code.
- Least amount of mapping.
- Least amount of repeated boilerplate code.
- Has "AddContents" method.
- "GetFriendlyString" functionality is available to ShoppingCartWithContents.
Con:
- It is not very clear what properties this tree of composed classes contains. To get to the Cart Id you have to dig through cartWithContents.ShoppingCart.Id.
using System;
using System.Collections.Generic;
using System.Linq;
namespace RoomGen
{
public class Room
{
public Map Map { get; private set; }
public Cell OriginCell { get; private set; }