Skip to content

Instantly share code, notes, and snippets.

View ogxd's full-sized avatar
👋

Olivier Giniaux ogxd

👋
View GitHub Profile
public class ManualOptionMonitor<T> : IOptionsMonitor<T>
{
private readonly Dictionary<int, Action<T, string>> _listeners = new Dictionary<int, Action<T, string>>();
private volatile int _nextId;
private T _currentValue;
public T CurrentValue
{
get
{
@ogxd
ogxd / cheatsheet.rs
Last active September 10, 2021 15:38
Rust Cheatsheet
//! Prints objects, cool for debugging
println!("{:#?}", my_object);
//! Empty struct shorthand
struct MyStruct;
@ogxd
ogxd / ThrottlingMiddleware.cs
Created April 29, 2021 10:05
ASP .NET Core middleware to do control rate, concurrency and throttling over incoming requests.
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace Ogxd
{
public class ThrottlingMiddleware
@ogxd
ogxd / SizeOfExtensions.cs
Created March 23, 2021 13:28
Measure size of an object through reflection
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.Reflection
{
public static class HashUtils
{
public static uint Lcg(uint value)
{
unchecked {
value = 1664525 * value + 1013904223;
return value;
}
}
@ogxd
ogxd / Screenshot.cs
Last active December 10, 2024 10:33
Unity Editor tool to take high quality screenshots with transparent background, high resolution and auto cropping.
using System.IO;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class Screenshot
{
static Screenshot()
{
EditorApplication.delayCall += () => {
@ogxd
ogxd / TransformExtensions.cs
Last active March 4, 2025 03:21
Get or set a Transform matrix using TRS decompositions
using UnityEngine;
public static class TransformExtensions {
private static void GetTRS(this Matrix4x4 matrix, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
{
float det = matrix.GetDeterminant();
// Scale
scale.x = matrix.MultiplyVector(new Vector3(1, 0, 0)).magnitude;
@ogxd
ogxd / Dispatcher.cs
Created October 3, 2019 16:46
Dispatcher for Unity
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.LowLevel;
#pragma warning disable CS1998
@ogxd
ogxd / MonoContext.cs
Last active March 9, 2020 21:49
Coroutines outside of Unity's component, global update callback & main thread dispatcher
using System;
using System.Collections.Concurrent;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
[ExecuteInEditMode]
public sealed class MonoContext : MonoBehaviour {
public static UnityEvent OnUpdate;
@ogxd
ogxd / Profiling.cs
Last active March 9, 2020 21:49
Display elasped time in a time interval.
using System;
using System.Collections.Generic;
using System.Diagnostics;
public static class Profiling {
private static Dictionary<string, Stopwatch> stopwatches = new Dictionary<string, Stopwatch>();
public static void Start(string key) {
if (!stopwatches.ContainsKey(key))