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 / dotnet_intrinsics_search.md
Last active September 10, 2021 12:31
Playing around with the new hardware intrinsics of .net core 3.0

.Net Core 3.0 (currently in preview) adds support for hardware intrinsics.

So now we can write simd instructions in c# 🎉

Intel has a nice website for browsing through the available instructions: Intel intrinsics guide

Everything from Avx2 down seems supported. (Given that your cpu supports it ofcourse)

For double checking what c# call maps to what instruction you can check the summary of the methods:

@BastianBlokland
BastianBlokland / unity_ios_verificationsignature.md
Last active February 16, 2024 22:19
Way to get the game-center verification signature with Unity.

Even tho Unity has implemented a game-center api (Social api) it doesn't have a way to generate a verification signature, which you need to use game-center as a authentication method.

Luckily the objective-c code required is pretty straight forward. (Apple documentation: generateIdentityVerificationSignature)

#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>

typedef void (*IdentityVerificationSignatureCallback)(const char * publicKeyUrl, const char * signature, int signatureLength, const char * salt, int saltLength, const uint64_t timestamp, const char * error);
@BastianBlokland
BastianBlokland / qmk-config-dz60.md
Last active March 10, 2019 09:41
Configuration for dz-60 keyboard

DZ-60 Keyboard mapping

Preview image

Hardware

  • Board: dz-60 rev-3 (usb-c) (QMK compatible)
  • Switches: Cherry browns
  • Caps: DSA blanks
  • Case: Kbd-fans
@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
@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 / 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 / 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 / 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_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 / 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