Skip to content

Instantly share code, notes, and snippets.

bd = branch --delete
bm = branch --merged
cbr = rev-parse --abbrev-ref HEAD
cm = commit -m
co = checkout
cob = checkout -b
comit = commit
g = grep --break --heading --line-number
lol = log --pretty=oneline --abbrev-commit --graph --decorate
ship = push
@exallium
exallium / Promise.kt
Created February 14, 2019 19:57
Quick and dirty Promise in Kotlin
sealed class Either<out L, out R> {
data class Left<out L>(val l: L) : Either<L, Nothing>()
data class Right<out R>(val r: R) : Either<Nothing, R>()
}
fun asdf() {
val p = Promise<Int> { resolve, reject ->
resolve(Either.Left(4))
}
@exallium
exallium / formdata.kt
Last active February 14, 2018 16:41
Attempt at expressing form input a little more concisely
import android.databinding.BindingAdapter
import android.support.design.widget.TextInputEditText
import android.support.design.widget.TextInputLayout
data class FormData<out D, R>(
val data: D,
val reason: R?,
private val _reasonToString: (R?) -> String = { "$it" }
) {
val isValid = reason != null
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
import Control.Compose
import Control.Monad.Trans.State.Lazy
import Data.Char
@exallium
exallium / trees.hs
Created August 13, 2017 02:49
playing around with trees to solidify working with instance declarations
data Tree a = Branch (Tree a) (Tree a) | Leaf a deriving Show
instance Functor Tree where
fmap fn (Branch l r) = Branch (fmap fn l) (fmap fn r)
fmap fn (Leaf a) = Leaf $ fn a
instance Applicative Tree where
(<*>) (Leaf fn) t = fmap fn t
(<*>) (Branch l r) t = Branch (l <*> t) (r <*> t)
pure = Leaf
data Parser = WebParser | DbParser
class ParseStrategy p where
parse :: p -> String -> String
instance ParseStrategy Parser where
parse WebParser s = "code for parsing web stuff goes here"
parse DbParser s = "code for parsing db stuff goes here"
fromDB = parse DbParser
@exallium
exallium / scan.kt
Created August 10, 2017 15:13
Quick and Dirty Scan function in Kotlin
fun <T> List<T>.scan(fn: (T, T) -> T): List<T> {
return if (this.isEmpty()) this
else this.drop(1).fold(listOf(this.first()), { acc, item ->
acc.plus(fn(acc.last(), item))
})
}
println((1..5).toList().scan { x, y -> x + y })
@exallium
exallium / firebaseRepo.kt
Last active June 20, 2017 17:21
Firebase Callback to Rx Observable
private class ValueEventListenerToEmitter(private val emitter: Emitter<DataSnapshot>) : ValueEventListener {
override fun onCancelled(error: DatabaseError) {
emitter.onError(error.toException())
}
override fun onDataChange(snapshot: DataSnapshot) {
emitter.onNext(snapshot)
}
}
@exallium
exallium / debounceEx2.kt
Last active March 17, 2017 15:13
debounceEx2
interface View {
fun clicks(): Observable<Unit>
}
interface Model {
fun submits(): Observable<Unit>
}
class Presenter(val view: View, val model: Model) {
fun setUp() {
@exallium
exallium / debouncetest.kt
Last active March 16, 2017 14:04
unit testing a debounce
@Test
fun debounce_test() {
// TestScheduler lets us control time ;)
val testScheduler = TestScheduler()
// This basically represents a button.
val testClicks = PublishSubject<Long>()
// This'll let us verify our interactions
val testSubscriber = TestSubscriber<Long>()