Skip to content

Instantly share code, notes, and snippets.

View Grinderofl's full-sized avatar

Nero Sule Grinderofl

View GitHub Profile
@Grinderofl
Grinderofl / stfu-vscode-install.ps1
Last active April 25, 2018 07:18
Actually auto update VSCode
#Setup-Install-VSCode
$url = "https://gist.githubusercontent.com/Grinderofl/0946997470f85f3a5598c5e20ef0c17d/raw/fa62828039e3b2431a7bacbf2618ac6fb6a1fa87/vscode-silent-update.ps1"
$taskName = "StfuVsCode"
$psFile = "vscode-silent-update.ps1"
$scriptPath = [io.path]::combine($env:LOCALAPPDATA, "Fixes", $psFile)
New-Item -Force -Path $scriptPath
Invoke-Webrequest $url -UseBasicParsing -OutFile $scriptPath
Import-Module ScheduledTasks
@Grinderofl
Grinderofl / gist:85a093d76530e205c9c1d56441ddc955
Last active March 20, 2018 09:10
EF Query raw linq vs queryable
// Works:
var jobs1 = (from job in _dbContext.Jobs
let latest = _dbContext.JobHistory
.OrderByDescending(x => x.CreatedOnUtc)
.FirstOrDefault(x => x.JobId == job.Id)
select new
{
JobTypeIdentifier = job.JobType.Id,
JobTypeName = job.JobType.Name,
JobTypeDescription = job.JobType.Description,
@Grinderofl
Grinderofl / RecentlyVisitedContentService.cs
Created March 19, 2018 13:32
Episerver recently visited content
[ServiceConfiguration(typeof(RecentlyVisitedContentService))]
public class RecentlyVisitedContentService
{
private static ApplicationEnvironmentContext EnvironmentContext => new ApplicationEnvironmentContext();
private static string CookieKey => $".DotComRecents.{EnvironmentContext.CurrentEnvironment}.Cookie";
private static int MaximumEntries => 100;
private readonly ICookieService _cookieService;
private readonly IContentRouteHelper _routeHelper;
@Grinderofl
Grinderofl / Webjob.cs
Created March 14, 2018 12:34
Automagically instrument Rebus with AppInsights and NewRelic
using Nr = NewRelic.Api.Agent.NewRelic;
private void ConfigureRebus(RebusConfigurerWithLogging configuration)
{
// ...
configuration.Events(ConfigureEvents);
// ...
}
public class MemoryCacheTicketStore : ITicketStore
{
private const string KeyPrefix = "AuthSessionStore-";
private readonly IMemoryCache _cache;
public MemoryCacheTicketStore()
{
_cache = new MemoryCache(new MemoryCacheOptions());
}
public IEnumerable<YourType> GetYourTypes()
{
yield return GetElement();
foreach(var el in GetOtherElements())
yield return el;
}
var types = GetYourTypes();
if(!types.Any()) // possible multiple enumerations of enumerable
public class AssemblaClientSettings
{
public string BaseUrl { get; set; } = "https://api.assembla.com/";
public string ApiKey { get; set; }
public string ApiSecret { get; set; }
}
@Grinderofl
Grinderofl / ServiceCollectionExtensions.cs
Created February 1, 2017 00:14
Castle Typed Factory for .NET Core
public static class ServiceCollectionExtensions
{
private static readonly IProxyGenerator ProxyGenerator = new ProxyGenerator(true);
public static IServiceCollection AddTypedFactory<T>(this IServiceCollection services, ServiceLifetime lifetime = ServiceLifetime.Transient) where T : class
{
services.TryAddSingleton<TypedFactoryInterceptor>();
services.Add(new ServiceDescriptor(typeof(T), CreateProxy<T>, lifetime));
return services;
}
@Grinderofl
Grinderofl / BehindTheScenes.cs
Last active December 13, 2016 20:27
Random way of building startup...
public static class WebHostBuilderExtensions
{
public static WebHostBuilder UseProspero(this WebHostBuilder builder, Action<ProsperoFeatures> featuresAction)
{
builder
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration();
builder.UseConventionAutofacServiceProvider(); // Finds Module subtypes
@Grinderofl
Grinderofl / IPostcodeLookupService.cs
Created December 6, 2016 10:02
Postcode lookup service
public interface IPostcodeLookupService
{
PostcodeLookup Lookup(string postcode);
}