View EF-AccessBgContext-Step1.cs
// 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; | |
} |
View i3-config
################################# | |
# 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 |
View latency.txt
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 |
View MassTransit.Scheduling.InMemory.cs
using System; | |
using System.Threading.Tasks; | |
using MassTransit; | |
using MassTransit.QuartzIntegration; | |
namespace MassTransit.InMemory.Scheduling | |
{ | |
public class ScheduledMessageConsumer : | |
IConsumer<ScheduledMessage> |
View aspnet-ai-telemetry-suppress-request.cs
// ********************************************** | |
// 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; |
View aspnet-ai-telemetry-suppress-init-dotnetcore.cs
// ********************************************** | |
// 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) | |
{ |
View aspnet-ai-telemetry-suppress-init.cs
// ********************************************** | |
// 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(); |
View aspnet-ai-telemetry-init.cs
// ********************************************** | |
// 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; |
View aspnet-ai-telemetry-trackEvent.cs
// ********************************************** | |
// 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(); | |
} |
View aspnet-ai-telemetry-trackException.cs
// ********************************************** | |
// 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>(); |
NewerOlder