Skip to content

Instantly share code, notes, and snippets.

View amoerie's full-sized avatar

Alexander Moerman amoerie

  • DOBCO Medical Systems
  • Belgium
View GitHub Profile
@amoerie
amoerie / Program.cs
Created October 11, 2022 12:11
Modify pixel data of an existing DICOM file by writing some text over it using ImageSharp
using DcmPixelData;
using FellowOakDicom;
using FellowOakDicom.Imaging;
using FellowOakDicom.Imaging.NativeCodec;
using FellowOakDicom.IO.Buffer;
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
@amoerie
amoerie / NetworkStreamBenchmarks.cs
Created November 24, 2021 09:27
NetworkStream vs BufferedStream benchmarks
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
namespace Gists
{
[MemoryDiagnoser]
@amoerie
amoerie / MiniProfiler.sql
Created May 5, 2021 07:28
Create MiniProfiler tables
CREATE TABLE MiniProfilers
(
RowId integer not null identity constraint PK_MiniProfilers primary key clustered, -- Need a clustered primary key for SQL Azure
Id uniqueidentifier not null, -- don't cluster on a guid
RootTimingId uniqueidentifier null,
Name nvarchar(200) null,
Started datetime not null,
DurationMilliseconds decimal(15,1) not null,
[User] nvarchar(100) null,
HasUserViewed bit not null,
@amoerie
amoerie / PriorityChannelTest.cs
Last active April 30, 2021 08:05
PriorityChannelTest - A proof of concept for a thread safe concurrent queue built on channels
using FluentAssertions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
@amoerie
amoerie / LogConfigOnStartup.cs
Created March 24, 2021 07:39
LogConfigOnStartup.cs
public class LogConfigOnStartup : IHostedService
{
private readonly ILogger<LogConfigOnStartup> _logger;
private readonly IConfigurationRoot _configuration;
public LogConfigOnStartup(ILogger<LogConfigOnStartup> logger, IConfiguration configuration)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_configuration = configuration as IConfigurationRoot ?? throw new ArgumentNullException(nameof(configuration));
}
@amoerie
amoerie / Rx.Observable.debug.ts
Created June 26, 2017 11:41
A nice, simple debug operator for RxJs 5.
import {Observable} from 'rxjs/Observable';
const isProduction: boolean = process && process.env && process.env.NODE_ENV === "production";
const debug = function <T>(this: Observable<T>, name: string) {
if (isProduction)
return this;
return this
.do({
next: (value: T) => {
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Wordlist {
public class Program {
@amoerie
amoerie / DateTime.java
Created November 3, 2015 09:53
Very simple datetime for Java (minimal port from C#)
public class DateTime implements Cloneable, Comparable<DateTime>,Parcelable {
public static DateTime today() { return now().withTimeAtStartOfDay(); }
public static DateTime now() { return new DateTime(Calendar.getInstance()); }
private final Calendar calendar;
@Override
public int compareTo(@NonNull DateTime another) {
return calendar.compareTo(another.calendar);
}
public class SmartBox {
private Map<Class, Class> bindings;
public SmartBox() {
this.bindings = new HashMap<>();
}
/**
* Binds {@TService} class to {@TInstance}
*
SmartBox smartBox = new SmartBox();
smartBox.bind(Warrior.class, Samurai.class);
smartBox.bind(Weapon.class, Nunchucks.class);
Warrior warrior = smartBox.get(Warrior.class);
warrior.fight();