Skip to content

Instantly share code, notes, and snippets.


Jesse Schalken jesseschalken

View GitHub Profile
jesseschalken / boolsToBraille.kt
Created Apr 29, 2021
Convert Booleans to a braille String in Kotlin Java Scala
View boolsToBraille.kt
fun Iterable<Boolean>.toBrailleString(): String =
chunked(8) {
fun p(i: Int, j: Int) =
if (i < it.size && it[i]) 1 shl j else 0
'\u2800' +
p(0, 0) + p(1, 1) + p(2, 2) + p(3, 6) +
p(4, 3) + p(5, 4) + p(6, 5) + p(7, 7)
View scope functions.kt
T.also(block: (T) -> Unit): T
T.apply(block: T.() -> Unit): T
T.let(block: (T) -> R): R T.() -> R): R
View Hashmap.ts
export interface HashImpl<T> {
hash?(value: T): unknown;
equals(a: T, b: T): boolean;
export class AssociationList<K, V> implements Map<K, V> {
private inner: {readonly key: K; value: V}[] = [];
private readonly impl: HashImpl<K>,
jesseschalken /
Created Jul 16, 2020
C++ pointer alternatives
C C++
T* owning a single object T
T* borrowing a single object T&
T* owning a single object, nullable std::optional<T>
T* owning a single object, polymorphic std::unique_ptr<T>
T* owning an array (dynamic size) std::vector<T>
T[N] owning an array (static size) std::array
View CircularBuffer.ts
export class CircularBuffer<T> implements Iterable<T> {
private start: number = 0;
private _length: number = 0;
private array: T[] = [];
grow(size: number) {
if (size > this.array.length) {
size = Math.max(size, this.array.length * 1.5);
const array = new Array<T>(size | 0);
for (const x of this) {

Random database IDs

I'm inferring this based on vague statements on the internet and a reading of how B-trees work.

Databases and file systems use B-tree indexes to implement key-value maps (indexes for a database table). Since it's a search tree and not a hash table, it is inherently ordered.

Cache locality

When inserting sequentially increasing values into a B-tree, you always hit the rightmost leaf node (sorting left to right), since that's where a value that is higher than all the existing values must be inserted. When the leaf is full, it is split in two and the parent node is updated to have an extra child. Since the parent may also already be full, it may need to be split, and so on. When the root node is full, it needs to be split, creating a new root and increasing the height of the tree by 1 level.

jesseschalken / utf ord chr.php
Created Feb 5, 2017
ord() and chr() for UTF-8
View utf ord chr.php
function utf8_ord(string $s, int $i = 0): int {
$b0 = 0b00000000;
$b1 = 0b10000000;
$b2 = 0b11000000;
$b3 = 0b11100000;
$b4 = 0b11110000;
$b5 = 0b11111000;
View SystemError.php
<?hh // strict
namespace HackUtils;
final class SystemError extends \RuntimeException {
const int EPERM = 1;
const int ENOENT = 2;
const int ESRCH = 3;
const int EINTR = 4;
const int EIO = 5;
View json_emit.php
function json_emit($x, $nl = "\n") {
if (is_array($x)) {
if (!$x)
return '[]';
$nl2 = $nl . ' ';
if (is_assoc($x)) {
$parts = array();
foreach ($x as $k => $v) {
View double-conversion.patch
diff --git a/PKGBUILD b/PKGBUILD
index 201632c..893f879 100644
@@ -4,27 +4,30 @@