Skip to content

Instantly share code, notes, and snippets.

View jiimaho's full-sized avatar
🎯
Focusing

Jim Aho jiimaho

🎯
Focusing
View GitHub Profile
app.UseSpa(spa =>
{
if (_environment.IsDevelopment())
{
// Make sure you have started the frontend with npm run dev on port 4000
spa.UseProxyToSpaDevelopmentServer("http://localhost:4000");
}
});
@jiimaho
jiimaho / Startup.cs
Last active December 15, 2019 18:42
Pseudocode example: relation between UseDefaultFiles, UseSpaStaticFiles and UseSpa
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "wwwroot";
});
// ...
}
@jiimaho
jiimaho / Startup.cs
Created December 15, 2019 22:19
Pseudocode: relation between UseDefaultFiles and UseStaticFiles
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
// ...
app.UseDefaultFiles();
app.UseStaticFiles();
// ...
}
@jiimaho
jiimaho / AnotherWorker.cs
Created April 8, 2020 06:12
BackgroundService and cancellation tokens
public class AnotherWorker : BackgroundService
{
private readonly IHostApplicationLifetime _hostApplicationLifetime;
public AnotherWorker(IHostApplicationLifetime hostApplicationLifetime)
{
_hostApplicationLifetime = hostApplicationLifetime;
}
public override Task StartAsync(CancellationToken cancellationToken)
@jiimaho
jiimaho / Makefile
Last active May 3, 2020 18:09
Publish nuget to local feed with Make
# Builds all nugets for easier local development
mac:
dotnet pack src/Your.Project.Here.csproj -o ~/localfeed
windows:
dotnet pack src/Your.Project.Here.csproj -o c:\localfeed
public class IgnoreRequestPathsTelemetryProcessor : ITelemetryProcessor
{
private readonly ITelemetryProcessor _next;
public IgnoreRequestPathsTelemetryProcessor(ITelemetryProcessor next)
{
_next = next;
}
public void Process(ITelemetry item)
@jiimaho
jiimaho / Startup.cs
Created May 31, 2020 18:28
Application Insights DI custom telemetry processor
public void ConfigureServices(IServiceCollection services)
{
// ....
services.AddApplicationInsightsTelemetry(Configuration);
services.AddApplicationInsightsTelemetryProcessor<IgnoreRequestPathsTelemetryProcessor>();
// ....
}
@jiimaho
jiimaho / gist:5f2ed26af284975f64ab46070a1e5ab9
Created December 21, 2020 11:56
.NET Core TimeZoneInfo.GetSystemTimeZones() id's
Pacific/Niue
Pacific/Midway
Pacific/Pago_Pago
America/Adak
Pacific/Rarotonga
Pacific/Tahiti
Pacific/Honolulu
Pacific/Marquesas
America/Metlakatla
America/Sitka
public class Function
{
private static ServiceProvider ServiceProvider { get; set; }
/// <summary>
/// The parameterless constructor is what Lambda uses to construct your instance the first time.
/// It will only ever be called once for the lifetime of the container that it's running on.
/// We want to build our ServiceProvider once, and then use the same provider in all subsequent
/// Lambda invocations. This makes things like using local MemoryCache techniques viable (Just
/// remember that you can never count on a locally cached item to be there!)
@jiimaho
jiimaho / Exception.cs
Created June 21, 2021 18:55
Bad logging of errror
try
{
// network call
}
catch(Exception e)
{
_logger.Error(e, "Network call failed");
}