Skip to content

Instantly share code, notes, and snippets.

View BastianBlokland's full-sized avatar
⌨️
Probably building something...

Bastian Blokland BastianBlokland

⌨️
Probably building something...
View GitHub Profile
@BastianBlokland
BastianBlokland / TypedTree-Editor-Launcher.md
Last active August 31, 2023 12:19
Tiny electron wrapper for the TypedTree-Editor

TypedTree-Editor electron wrapper

Tiny electron wrapper around the typedtree-editor (repo).

Advantage is that it allows local filesystem access so it can write changes back to the original file. Atleast untill native-file-system api has become mainstream in browsers.

Usage

On unix systems execute run.sh, on others run npm install and npm start.

@BastianBlokland
BastianBlokland / qmk-config-nyquist.md
Last active September 23, 2021 07:21
Configuration for nyquist keyboard

Nyquist Keyboard mapping

Preview image Preview image

Hardware

  • Board: Nyquist rev3
  • Switches: Zealios 62g v2
  • Caps: DSA blanks
  • Case: KPrepublic SP50 case
@BastianBlokland
BastianBlokland / writeint-benchmark.md
Last active September 10, 2021 12:31
Perf difference of different ways of serializing a integer in dotnet.

Perf difference of different binary serialization methods

Quick benchmark to see the performance difference between the different ways of 'serializing' data to a binary blob in dotnet. For simplicity this only deals with writing 32 bit integers.

Methods this compares:

  • Shifting and assigning the four bytes that make up the integer.
  • Using MemoryMarshal to write the memory.
  • Directly assigning a reference.
  • Directly assigning a pointer.
@BastianBlokland
BastianBlokland / binserialize.md
Last active November 30, 2023 02:53
Span<byte> based binary serialization
MIT License

Copyright (c) 2019 Bastian Blokland

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@BastianBlokland
BastianBlokland / dotnet_cached-delegate_benchmark.md
Last active September 10, 2021 12:31
Does caching of delegates in high-frequency c# make sense?

Benchmark to test if caching delegates in high-frequence code has any benefit.

so:

Print42(ConsolePrint);

void ConsolePrint(string text) => Console.WriteLine(text);

void Print42(Action<string> print) => print("42");
@BastianBlokland
BastianBlokland / dotnet_synchronized_channel.md
Last active October 30, 2019 14:28
General purpose thread-safe event channel class for distributing events based on type.

General purpose thread-safe event channel class for distributing events based on type.

Uses the SynchronizedEvent<T> class from an earlier gist.

This builds on the features of the SynchronizedEvent<T> and adds distributing events based on type. This is usefull when for example you want to have a publisher for a generic type (like IMessage) and then allow subscribing to derrived types (like NameChangedMessage).

Example:

@BastianBlokland
BastianBlokland / dotnet_synchronized_event.md
Last active October 30, 2019 14:28
General purpose thread-safe event class.

General purpose thread-safe event class.

Features:

  • Thread-safety.
  • Supports capturing the SyncronizationContext (Which makes it useable in the Unity3d engine).
  • Provides a Task<T> api for waiting for events.
  • Provides a callback (Subscribe / Unsubscribe) api for receiving events.
  • Reasonable performance.
  • Ability to pass a custom subscriptionToken makes it easier to unsubscribe lambda's.
  • Supports storing data that was invoked when no-one was subscribed (or waiting) yet.
@BastianBlokland
BastianBlokland / unity_sync_context_helper.md
Last active July 9, 2019 17:15
Utility to execute code on the unity-thread from background threads.

Dotnet's async task programming model makes it much easier to write multi-threaded code, unfortunatly Unity's api's don't like to be called from non-Unity threads. For example you might have some background task to open a connection and then you realize you need to access Unity's PlayerPrefs api to get some key for example.

This utility makes that scenario easier by providing a api for executing code on Unity's syncronization context and handing you back a convient task to track when the code has been executed.

For example:

private async Task BackgroundWorkAsync()
@BastianBlokland
BastianBlokland / profile_dotnet.md
Last active June 5, 2019 08:10
Profile dotnet application using 'dotnet-trace'

Starting from dotnet core 2.1 the dotnet runtime emits profiling events through the EventPipe api. And there is now a convient and cross platform way to consume those: dotnet-trace.

This little script automates the process of installing dotnet-sdk dependencies, installing a sdk and installing the dotnet-trace tool. At the moment this works for debian based distributions but can be expanded to different distributions.

Show help:

curl -sSL -o ./pd.sh https://bastian.tech/scripts/profile-dotnet.sh && chmod +x ./pd.sh && ./pd.sh -h
@BastianBlokland
BastianBlokland / qmk-config-jj40.md
Last active September 23, 2021 07:22
Configuration for jj40 keyboard

JJ-40 Keyboard mapping

Preview image Preview image

Hardware

  • Board: jj-40 v1.5 (QMK compatible)
  • Switches: Zealios 62g
  • Caps: DSA blanks
  • Case: KPrepublic Aluminium