Skip to content

Instantly share code, notes, and snippets.

@cocowalla
cocowalla / open-telemetry-config.cs
Created May 31, 2023 14:10
A rough example of how to use Serilog.Sinks.OpenTelemetry to send logs to Azure Application Insights
builder
.UseSerilog((ctx, _, logConfig) =>
{
logConfig.ReadFrom.Configuration(ctx.Configuration, "Log");
}, writeToProviders: true)
.ConfigureServices((ctx, services) =>
{
services.AddOpenTelemetry()
.ConfigureResource(res => {
...
@cocowalla
cocowalla / ExponentialWeightedMovingAverage.cs
Created May 7, 2021 10:23
Exponential Weighted Moving Average
public class ExponentialWeightedMovingAverage
{
private bool isInitialized;
// Smoothing/damping coefficient
private double alpha;
public double Average { get; private set; }
public ExponentialWeightedMovingAverage(int samplesPerWindow)
@cocowalla
cocowalla / data-classification.sql
Created February 5, 2021 09:08
Conditional SQL Server Data Classification
DECLARE @compatibility_level TINYINT = 0;
SELECT @compatibility_level = compatibility_level FROM sys.databases WHERE name = 'MyDatabase';
PRINT CONCAT('Database compatibility level is: ', @compatibility_level);
IF @compatibility_level < 150
BEGIN
RAISERROR('Data Classification will not be performed, as database compatibility level %d is not high enough', 10, 1, @compatibility_level);
SET NOEXEC ON;
END;
GO
@cocowalla
cocowalla / Ecies.cs
Last active June 22, 2024 14:07
Simple ECIES implementation
using System;
using System.Security.Cryptography;
// ReSharper disable SuggestVarOrType_SimpleTypes - BCL rules
namespace Crypto
{
/// <summary>
/// Simple implementation of ECIES (Elliptic Curve Integrated Encryption Scheme) based on http://www.secg.org/sec1-v2.pdf, section 5.1
/// Things not implemented:
/// - Encoding parameters using compressed points; only uncompressed points are used
@cocowalla
cocowalla / bsod-report.html
Created August 10, 2019 15:04
BSOD report for mac-precision-touchpad
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head><title>Crash List</title></head>
<body>
<h3>Crash List</h3>
<br><h4>Created by using <a href="http://www.nirsoft.net/" target="newwin">BlueScreenView</a></h4><p><table border="1" cellpadding="5"><tr bgcolor="E0E0E0">
<th>Dump File
<th>Crash Time
<th>Bug Check String
<th>Bug Check Code
<th>Parameter 1
@cocowalla
cocowalla / WyHash64.cs
Created July 10, 2019 19:46
Wyhash incremental hash
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
// ReSharper disable InconsistentNaming
// ReSharper disable SuggestVarOrType_BuiltInTypes
namespace WyHash
{
/// <inheritdoc />
/// <summary>
@cocowalla
cocowalla / code.asm
Created May 8, 2019 10:32
SIMD XOR Optimisation
; Core CLR v4.6.27615.73 (coreclr.dll) on amd64.
MyClass..ctor()
L0000: push rbp
L0001: sub rsp, 0x20
L0005: lea rbp, [rsp+0x20]
L000a: mov [rbp+0x10], rcx
L000e: cmp dword [rip+0xbffb], 0x0
L0015: jz L001c
L0017: call 0x7ffc61fad9e0
@cocowalla
cocowalla / Maths.cs
Last active April 23, 2023 15:07
64-bit integer multiplication
// Non-intrinsics path is based on https://stackoverflow.com/a/51587262/25758, which is faster than any other portable 64-bit multiplication function I've found
public static class Maths
{
/// <summary>
/// Multiplies 2 unsigned 64-bit integers, returning the result in 2 ulongs representing the hi and lo bits
/// of the resulting 128-bit integer
/// </summary>
/// <remarks>
/// <seealso cref="System.Numerics.BigInteger"/> can perform multiplication on large integers, but it's
@cocowalla
cocowalla / Dockerfile
Last active November 7, 2022 15:38
TimescaleDB on debian stretch-slim
# Docker image for PostgreSQL with the TimescaleDB extensions installed, running on a Debian Stretch-Slim base
# Begin by building TimescaleDB
FROM postgres:11.2 AS build
ENV TIMESCALEDB_VERSION 1.2.2
ENV TIMESCALEDB_SHASUM="c8e8071c24707e3fa8a50abb788c85d03a1bd9d9dea2e273b4abf407f39c182a timescaledb-${TIMESCALEDB_VERSION}.tar.gz"
RUN buildDeps="curl build-essential ca-certificates git python gnupg libc++-dev libc++abi-dev pkg-config glib2.0 cmake libssl-dev" \
&& apt-get update \
@cocowalla
cocowalla / EnumExtensions.cs
Created February 4, 2019 19:44
Enum display name extension method
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Acme.Utils
{
public static class EnumExtensions