Skip to content

Instantly share code, notes, and snippets.

public class Opt<T> {
public interface Function<T> {
void apply(T object);
}
private final T object;
public Opt(T object) {
this.object = object;
@exallium
exallium / createButton.kt
Created January 14, 2016 19:29
JavaFX Button Column Creation in Kotlin
public fun <T> createButtonColumn(title: String, text: String, onClick: (T) -> Unit): TableColumn<T, T> {
val buttonColumn = TableColumn<T, T>(title)
buttonColumn.cellValueFactory = Callback { ReadOnlyObjectWrapper<T>(it.value) }
buttonColumn.cellFactory = Callback {
val button = Button()
object : TableCell<T, T>() {
override fun updateItem(item: T?, empty: Boolean) {
super.updateItem(item, empty)
@exallium
exallium / monads.kt
Created September 21, 2016 18:47
monads
package main;
sealed class Maybe<A>(private val a: A?) {
class Just<A>(a: A) : Maybe<A>(a) {
override fun toString() = "Just(${wrapped()})"
}
class None<A> : Maybe<A>(null) {
override fun toString() = "None"
}
#!/usr/bin/python
import subprocess
EXCLUDE = ["patrick-video-player-integration"]
GET_MERGED_BRANCHES = ["git", "branch", "--merged"]
DELETE_BRANCH = ["git", "branch", "--delete"]
PRUNE_ORIGIN = ["git", "remote", "prune", "origin"]
def runSubProc(proc):
@exallium
exallium / .gitconfig
Last active October 19, 2016 13:54
Clean all merged branches and prune origin
# Allows us to call the script via git bp
[alias]
bp = !~/clean_merged_branches.py
// Database interface
interface Database {
fun getUserById(id: String): Observable<User>
fun getAllUsers(): Observable<List<User>>
fun getUserChangeEvents(): Observable<ChangeEvent<User>>
}
// Describes what happened to what item
data class ChangeEvent<T>(val eventType: ChangeEventType, val t: T)
@exallium
exallium / Either.kt
Last active November 21, 2016 14:42
sealed class Either<L, R> {
class Left<L, R>(val l: L) : Either<L, R>() {
override fun toString(): String = "Left $l"
}
class Right<L, R>(val r: R) : Either<L, R>() {
override fun toString(): String = "Right $r"
}
infix fun <Rp> bind(f: (R) -> (Either<L, Rp>)): Either<L, Rp> {
@exallium
exallium / rxmvp.kt
Created January 4, 2017 17:45
rxmvp
interface Model {
fun first10Users(): Observable<List<Data>>
}
interface View {
fun displayUserList(users: List<Data>)
fun backButtonClicks(): Observable<ClickEvent>
}
class Presenter {
@exallium
exallium / rx_infinite.kt
Created January 5, 2017 19:57
Infinite Rx Sequence Usage
@Test
fun rx_infinite() {
val testSub = TestSubscriber<Int>()
var start = 0
fun inc(): Int {
start += 1
return start
}
@exallium
exallium / verifier.kt
Created January 17, 2017 19:34
Simple Monoid Verifier
// Our Monoid interface, which provides an "append" and "empty"
interface Monoid<M> {
fun append(l: M, r: M): M
fun empty(): M
}
sealed class ValidationResult {
companion object : Monoid<ValidationResult> {
// Appends two validation results. If both are failures, append messages with newline