Skip to content

Instantly share code, notes, and snippets.

View rasmuskl's full-sized avatar

Rasmus Kromann-Larsen rasmuskl

View GitHub Profile
@rasmuskl
rasmuskl / HumioSerilogSink.cs
Created November 22, 2018 20:19
A Humio Sink for Serilog
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Serilog;
@rasmuskl
rasmuskl / autobind.ts
Last active January 20, 2021 08:10
TypeScript autobind decorator
function autobind<TFunction extends Function>(constructor: TFunction):TFunction {
const newConstructor = function(...args) {
constructor.apply(this, args);
for (const property in this) {
if (typeof this[property] !== typeof Function) {
continue;
}
this[property] = this[property].bind(this);
}
@rasmuskl
rasmuskl / LogEventJsonConverter.cs
Last active March 16, 2021 21:57
Json.NET JsonConverters for deserializing Serilog's LogEvents.
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog.Events;
using Serilog.Parsing;
@rasmuskl
rasmuskl / XamarinTestCloudHooks.cs
Last active August 29, 2015 14:19
SpecFlow XTC screenshot workaround
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Bindings;
using TechTalk.SpecFlow.Bindings.Reflection;
using TechTalk.SpecFlow.Tracing;
using Xamarin.UITest;
using Xamarin.UITest.Events;
@rasmuskl
rasmuskl / SystemTime.cs
Created July 8, 2013 08:53
Mockable DateTime.UtcNow
public static class SystemTime
{
private static ITimeProvider _timeProvider = new RealTimeProvider();
public static DateTime UtcNow
{
get { return _timeProvider.UtcNow; }
}
public static IDisposable MockTime(DateTime utcNow)
@rasmuskl
rasmuskl / Autofac.cs
Created February 11, 2013 12:56
Autofac simple registration
// Conventionally register types implementing a single I[Classname] interface.
builder.RegisterAssemblyTypes(assemblies)
.Where(x => x.GetInterfaces().Count() == 1 && x.GetInterface("I" + x.Name) != null)
.AsImplementedInterfaces();
// Register types as themselves.
builder.RegisterAssemblyTypes(assemblies)
.AsSelf();
@rasmuskl
rasmuskl / profile.ps1
Last active October 11, 2015 02:08
VSH + NP + git PowerShell
# Load posh-git profile
. 'C:\Projects\Tools\posh-git\profile.example.ps1'
function vsh() {
Write-Output "Opening first solution..."
$sln = (dir -in *.sln -r | Select -first 1)
Write-Output "Found $($sln.FullName)"
Invoke-Item $sln.FullName
}
@rasmuskl
rasmuskl / fnv64a1.cs
Created September 26, 2012 07:39
FNV 1a 64-bit C# non-cryptographic hash
// FNV-1a (64-bit) non-cryptographic hash function.
// Adapted from: http://github.com/jakedouglas/fnv-java
public ulong HashFNV1a(byte[] bytes)
{
const ulong fnv64Offset = 14695981039346656037;
const ulong fnv64Prime = 0x100000001b3;
ulong hash = fnv64Offset;
for (var i = 0; i < bytes.Length; i++)
{
@rasmuskl
rasmuskl / check.js
Created May 8, 2012 11:59
JavaScript img internet connectivity check
$('<img>')
.on('load', function() { console.log('image loaded'); })
.attr('src', 'http://www.google.com/favicon.ico?'+(new Date()).getTime());
@rasmuskl
rasmuskl / monitor_stpem.bat
Created January 17, 2012 09:32
Set up ADPlus monitor for specific user process
@echo OFF
set PID="No"
for /F "tokens=1-2" %%A in ('tasklist /FI "USERNAME eq stpem" /FI "IMAGENAME eq PROASK.Client.Shell.exe" /NH') do (
echo Found process: %%A - PID: %%B
set PID="%%B"
)
IF %PID% == "No" GOTO :EOF