Skip to content

Instantly share code, notes, and snippets.

View hd9's full-sized avatar

Bruno Hildenbrand hd9

View GitHub Profile
@hd9
hd9 / EF-AccessBgContext-Step1.cs
Created October 18, 2019 17:41
Accessing Entity Framework context on the background on .NET Core
// Step 1 - Inject IServiceScopeFactory in your controller
// Source: https://blog.hildenco.com/2018/12/accessing-entity-framework-context-on.html
private readonly IServiceScopeFactory serviceScopeFactory;
public ApiController(ApplicationDbContext context, IServiceScopeFactory serviceScopeFactory)
{
this.context = context;
this.serviceScopeFactory = serviceScopeFactory;
}
#################################
# Source: https://blog.hildenco.com/2019/08/how-i-fell-in-love-with-i3.html
#################################
# start a terminal
bindsym $mod+Return exec gnome-terminal
# kill focused window
bindsym $mod+x kill
@hd9
hd9 / latency.txt
Created June 30, 2020 20:05 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@hd9
hd9 / MassTransit.Scheduling.InMemory.cs
Created May 22, 2018 06:23
MassTransit InMemory Scheduling App using RabbitMQ and .Net Core
using System;
using System.Threading.Tasks;
using MassTransit;
using MassTransit.QuartzIntegration;
namespace MassTransit.InMemory.Scheduling
{
public class ScheduledMessageConsumer :
IConsumer<ScheduledMessage>
@hd9
hd9 / aspnet-ai-telemetry-suppress-request.cs
Last active February 19, 2020 17:26
Suppressing Application Insights telemetry on an ASP.NET Core web applications
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/suppressing-application-insights.html
// **********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.Channel;
@hd9
hd9 / aspnet-ai-telemetry-suppress-init-dotnetcore.cs
Last active February 19, 2020 16:14
Suppressing Application Insights telemetry on an ASP.NET Core web applications
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/suppressing-application-insights.html
// **********************************************
// To register your custom telemetry processor, update the
// ConfigureServices on your Startup.cs class adding your custom
/// telemetry processor. Ex: SuppressFaviconFilter
public void ConfigureServices(IServiceCollection services)
{
@hd9
hd9 / aspnet-ai-telemetry-suppress-init.cs
Last active February 19, 2020 15:49
Suppressing Application Insights telemetry on an ASP.NET web applications
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/suppressing-application-insights.html
// **********************************************
// add this on your Global.asax
var builder = TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
builder.Use((next) => new SuppressFaviconFilter(next));
builder.Build();
@hd9
hd9 / aspnet-ai-telemetry-init.cs
Last active February 18, 2020 22:02
Initializing Application Insights telemetry on an ASP.NET Core web application
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/03/adding-application-insights-telemetry.html
// **********************************************
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly TelemetryClient _telemetry;
@hd9
hd9 / aspnet-ai-telemetry-trackEvent.cs
Last active February 18, 2020 22:02
Posting a custom event from an ASP.NET Core web application to Application Insights
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/03/adding-application-insights-telemetry.html
// **********************************************
public IActionResult Privacy()
{
_telemetry.TrackEvent($"Privacy requested @ {DateTime.UtcNow} UTC");
return View();
}
@hd9
hd9 / aspnet-ai-telemetry-trackException.cs
Last active February 18, 2020 22:02
Handling exceptions on ASP.NET Core web posting to Application Insights
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/03/adding-application-insights-telemetry.html
// **********************************************
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
// IExceptionHandlerPathFeature requires Microsoft.AspNetCore.Diagnostics
// run: dotnet add package Microsoft.AspNetCore.Diagnostics --version 2.2.0
var error = HttpContext.Features.Get<IExceptionHandlerFeature>();