Skip to content

Instantly share code, notes, and snippets.

@Wouterdek
Wouterdek / RefCountedFlags.cs
Created June 2, 2021 08:55
RefCountedFlags
using System;
/// <summary>
/// Provides a boolean value for each value in an enum,
/// but setting the same flag twice means the flags needs to be unset twice to be false
/// </summary>
/// <typeparam name="T">An enum type (optionally with [Flags]) backed by a 32bit int</typeparam>
public unsafe struct RefCountedFlags<T> where T : Enum //T must be backed by a 32bit int
{
fixed byte counts[32];
@Wouterdek
Wouterdek / clang-update-alternatives.sh
Created May 5, 2021 15:51
clang-12-update-alternatives-script
# Like https://github.com/toprakkeskin/clang-8-update-alternatives-script/blob/master/clang-update-alternatives.sh
# but for LLVM/Clang 12
# llvm
sudo update-alternatives \
--install /usr/lib/llvm llvm /usr/lib/llvm-12 20 \
--slave /usr/bin/llvm-addr2line llvm-addr2line /usr/bin/llvm-addr2line-12 \
--slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-12 \
--slave /usr/bin/llvm-as llvm-as /usr/bin/llvm-as-12 \
--slave /usr/bin/llvm-bcanalyzer llvm-bcanalyzer /usr/bin/llvm-bcanalyzer-12 \
@Wouterdek
Wouterdek / nn_serialization.txt
Created July 17, 2018 08:18
NodeNetwork automatic viewmodel serialization problem
Deserializing objects using Json.NET first calls a constructor, and then a OnDeserialized callback if defined.
If an object has a property that has the OnDeserialized callback,
then first both objects (parent and property) are constructed and then the callback is called on both.
ReactiveUI has several classes that define a OnDeserialized callback.
These classes, however, were not designed to use Json.NET but rather the build in serializer.
The difference between the two is that the latter does not first call the constructor on deserialization, but rather only the callback.
This means that deserializing ReactiveUI objects using Json.NET leads to unexpected behaviour, such as properties getting set twice, getting reset, ...
Bindings, observers, ... that were made in constructors get overriden.
A solution should be:
@Wouterdek
Wouterdek / BitList.cs
Last active July 12, 2018 14:14
C# BitList: Used like IList<bool>, stores like BitArray.
//TODO: debug (check for mismatches in counting in bits/bytes/ints)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
[Serializable]
public class BitList : IList<bool>, ICloneable
{
@Wouterdek
Wouterdek / FontAwesomeIcons.cs
Created July 17, 2015 08:26
FontAwesome C# icon class
public enum FontAwesomeIcons {
Adjust = 0xf042,
Adn = 0xf170,
AlignCenter = 0xf037,
AlignJustify = 0xf039,
AlignLeft = 0xf036,
AlignRight = 0xf038,
Ambulance = 0xf0f9,
Anchor = 0xf13d,
Android = 0xf17b,