Skip to content

Instantly share code, notes, and snippets.

View jessestricker's full-sized avatar

Jesse Stricker jessestricker

  • Hamburg, Germany
  • 12:34 (UTC +02:00)
View GitHub Profile
@jessestricker
jessestricker / enum.cs
Last active April 20, 2016 19:42
[C#] A generic util class for enums.
using System;
using System.Collections.Generic;
using System.Linq;
public static class Enum<T> where T : struct
{
public static IEnumerable<EnumValue<T>> Values =>
from object value in Enum.GetValues(typeof(T))
select new EnumValue<T>((T)value);
@jessestricker
jessestricker / BindableBase.cs
Created May 5, 2016 10:55
[C# UWP] A base class for all view models.
/// <summary>
/// Implementation of <see cref="INotifyPropertyChanged" /> to simplify models.
/// </summary>
public abstract class BindableBase : INotifyPropertyChanged
{
/// <summary>
/// Multicast event for property change notifications.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
@jessestricker
jessestricker / OpenSimplexNoise.cpp
Created July 13, 2016 18:41
[C++] OpenSimplexNoise
#include "OpenSimplexNoise.hpp"
#include <cmath> // sqrt
#include <numeric> // std::iota
#include <algorithm> // std::shuffle
const OpenSimplexNoise::value_t
OpenSimplexNoise::STRETCH_CONST = (sqrt(3) - 3) / 6,
OpenSimplexNoise::SQUISH_CONST = (sqrt(3) - 1) / 2;
const std::array<OpenSimplexNoise::gradient, 8> OpenSimplexNoise::GRADIENTS =
@jessestricker
jessestricker / bcfmt.go
Created August 24, 2016 16:16
Byte Count Formatting
package util
import "fmt"
type ByteCount uint64
func (bc ByteCount) String() string {
const (
unitNames = "BKMGTPE" // E is sufficient for 64 bit values
maxValue = 1024
@jessestricker
jessestricker / cast_util.hpp
Last active November 16, 2016 23:21
Util Functions for Type Casting: pointer-to-pointer & enum-integral
#pragma once
#include <type_traits>
// ======== enum_cast
template <class E>
constexpr std::enable_if_t<std::is_enum<E>::value, std::underlying_type_t<E>> enum_cast(E e) noexcept
{
return static_cast<std::underlying_type_t<E>>(e);
@jessestricker
jessestricker / utf8.cpp
Created August 18, 2017 21:46
UTF-8 Decoding in C++
#include "utf8.hpp"
namespace {
template<class T>
struct range {
T low, high;
constexpr bool is_in(T value) const {
return low <= value && value <= high;
}
@jessestricker
jessestricker / USN.md
Last active April 17, 2018 11:07
Unicode Syntax Notification — Specification

Unicode Syntax Notification — Specification

TODO: Add introduction paragraph.

1 Term Definitions

  • 1.1 Character: The smallest possible matchable unit. Defined as a Unicode Scalar Value.
  • 1.2 Property: A binary character property as defined by Unicode. It's value is a closed range of all characters, which have this property set to true.
@jessestricker
jessestricker / print_int.c
Created October 30, 2017 20:14
GSP: Print integer values with a specific scale
#include <stdint.h>
#include <stdio.h>
void print_int(const int64_t v) {
const bool neg = v < 0;
uint64_t pv = neg ? -v : v;
// convert into digit characters
static const size_t DIGITS_LENGTH = 19;
char digits[DIGITS_LENGTH];
@jessestricker
jessestricker / .clang-format
Last active February 8, 2020 15:21
Code Style for C and C++
BasedOnStyle: WebKit
Language: Cpp
Standard: Cpp11
UseTab: Never
ColumnLimit: 120
AlignEscapedNewlines: Left
NamespaceIndentation: All
@jessestricker
jessestricker / llvm-toolchain.cmake
Created May 23, 2020 01:02
CMake Toolchain File for LLVM, using Clang, libc++, lld and LTO
set(flags "-flto")
set(c_flags "")
set(cxx_flags "-stdlib=libc++")
set(link_flags "-fuse-ld=lld")
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_C_FLAGS_INIT "${c_flags} ${flags}")
set(CMAKE_CXX_FLAGS_INIT "${cxx_flags} ${flags}")
set(CMAKE_EXE_LINKER_FLAGS_INIT "${link_flags}")