Skip to content

Instantly share code, notes, and snippets.

View breandan's full-sized avatar
📖
I may be slow to respond.

breandan breandan

📖
I may be slow to respond.
View GitHub Profile
@steveash
steveash / PreshingRandomSequence.java
Last active February 17, 2023 23:05
Pseudo-random generator that doesn't repeat integers
import java.util.Random;
/**
* Generates a sequence of pseudo-random numbers such that they never repeat. Can handle sequence sizes up to
* length Int.MAX_VALUE. Will throw exceptions if you ask for more than that; maps the entire [0, Integer.MAX_VALUE]
* range onto itself but in a random order
* <link>http://preshing.com/20121224/how-to-generate-a-sequence-of-unique-random-integers/</link>
*/
public class PreshingRandomSequence {
public static final int MAX_INT_PRIME = 2147483587;
@buzztaiki
buzztaiki / trampoline.kt
Created February 26, 2016 11:15
kotlinでとらんぽりん
sealed class Trampoline<A> {
class More<A>(val fn: () -> Trampoline<A>): Trampoline<A>() {
override fun toString() = "More"
}
class Done<A>(val a: A): Trampoline<A>() {
override fun toString() = "Done($a)"
}
companion object {
fun <A> run(fn: () -> Trampoline<A>): A = run(fn()).let {
@tylerneylon
tylerneylon / .block
Last active May 3, 2024 01:21
Quick js code to draw math functions in an SVG element.
license: mit
@hediet
hediet / main.md
Last active April 7, 2025 18:00
Proof that TypeScript's Type System is Turing Complete
type StringBool = "true"|"false";


interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };

type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];
@rxwei
rxwei / GADT.swift
Last active November 28, 2024 19:15
GADT in Swift
/// A type equality guarantee is capable of safely casting one value to a
/// different type. It can only be created when `S` and `T` are statically known
/// to be equal.
struct TypeEqualityGuarantee<S, T> {
private init() {}
/// Safely cast a value to the other type.
func cast(_ value: T) -> S {
return value as! S
}
@elizarov
elizarov / MultiShotEnumeration.kt
Created May 3, 2017 09:01
Showcase for Kotlin multishot continuations
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
fun main(args: Array<String>) {
enumerate {
if (flip("A")) {
if (flip("B")) 1 else 2
} else {
if (flip("C")) 3 else if (flip("D")) 4 else 5
}
@AndyShiue
AndyShiue / CuTT.md
Last active January 29, 2025 14:35
Cubical type theory for dummies

I think I’ve figured out most parts of the cubical type theory papers; I’m going to take a shot to explain it informally in the format of Q&As. I prefer using syntax or terminologies that fit better rather than the more standard ones.

Q: What is cubical type theory?

A: It’s a type theory giving homotopy type theory its computational meaning.

Q: What is homotopy type theory then?

A: It’s traditional type theory (which refers to Martin-Löf type theory in this Q&A) augmented with higher inductive types and the univalence axiom.

@thomasnield
thomasnield / calling_kotlin_from_python.py
Created June 2, 2018 23:09
Calling Kotlin from Python
os.system("kotlinc src/main/kotlin/Launcher.kt -include-runtime -d launcher.jar")
process = Popen(['java', '-jar', 'launcher.jar', tmp_file_name], stdout=PIPE)
(stdout, stderr) = process.communicate()
@bastman
bastman / cartesianProduct.kt
Last active November 11, 2023 07:14
Kotlin collections - leftJoin,innerJoin, ...
infix fun <T,O>List<T>.cartesianProduct(others:List<O>):List<Pair<T,O>> =
flatMap{ t:T->
others.map { o-> Pair(t,o) }
}
inline fun <T, O, R> List<T>.mapCartesianProduct(others: List<O>, transform: (Pair<T, O>) -> R): List<R> =
flatMap { t: T ->
others.map { o -> transform(Pair(t, o)) }
}
@rxwei
rxwei / ad-manifesto.md
Last active December 6, 2024 16:54
First-Class Automatic Differentiation in Swift: A Manifesto