Skip to content

Instantly share code, notes, and snippets.

Runtime Create Process
C++ 0.30 0.13
HL 1.35 0.36
JS 0.55 0.07
@saem
saem / nonRepeating.kt
Last active February 10, 2019 03:24
Use a kotlin scratchpad for this or write a quick main
fun nonRepeating(string: String): Int {
return when (string.length) {
0 -> 0
1 -> 1
else -> nonRepeatingActual(string, 0, 1)
}
}
fun nonRepeatingActual(
string: String,
@saem
saem / propose_accept_learn.js
Created August 1, 2016 03:35
Read about State, Action, Model (http://sam.js.org/), which is fashioned after TLA+'s concept of a step, I'm borrowing Paxos terminology: Propose, Accept, Learn as a step breakdown. Just doing some thinking out loud.
//@flow
/**
* The model, broken down into three parts (data, ui, & effects).
*
* data - canonical representation/interface with various backends.
* ui - the UI state
* effects - effects we want to trigger
*
* Model should probably be a parameterized type
@saem
saem / Thoughts.java
Created July 25, 2016 02:02
Initial thoughts on how to merge my thinking around Aggregates (named transaction boundaries), Entity-Component-Systems, and Relational Databases. This will evolve over time, it's currently incomplete.
public final class Thoughts { private Thoughts() {} }
/**
* # Introduction
*
* A number of thoughts/concerns floating in my head:
* 1 - DDD Aggregates, specifically transaction boundaries [1]
* 2 - Entity-Component-Systems, how games are data oriented, high performance
* databases [2][3]
* 3 - How 1 & 2 work with relational databases
@saem
saem / TimestampToOptionalInstantBinder.java
Created July 13, 2016 21:26
JOOQ MySQL DateTime Converter to handle '0000-00-00 00:00:00', which are returned as null, if configured, by JDBC. The code should be modified to not throw an exception if the field is nullable.
/**
* This code hasn't been tested, but this gives you an idea of what to throw together to get this to work
*
* You also need to go into your jooq generator config and setup the following:
*
* <forcedTypes>
* <forcedType>
* <name></name>
* <expression>(?i:Table.field)</expression>
* <types>(?i:DATETIME(\s*\(\d+\))?)</types>
@saem
saem / Try.java
Last active August 29, 2015 14:04
A first attempt at a Try type in Java, based on initial code from (http://java.dzone.com/articles/whats-wrong-java-8-part-iv). Heavily inspired by the API of Optional (http://docs.oracle.com/javase/8/docs/api/java/util/Optional.html). Updated thanks to input from @AlexCruise and @J1459
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
public abstract class Try<T> {
private Try() {