Skip to content

Instantly share code, notes, and snippets.

import java.io.IOException;
import java.util.List;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func0;
import rx.functions.Func1;
package iter
import java.io.File
import kotlin.coroutines.experimental.buildSequence
fun main(args: Array<String>) {
val file = File("path-to/access-log")
val linesInFile = getLines(file)
val bytesColumn = getBytesColumn(linesInFile)
val bytes = getBytes(bytesColumn)
package generator
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun kotlincoro() = generate<String, String>{
println("[ coroutine ]: started")
println("[ coroutine ]: suspended at first yield and sent data to main")
val coroData = yield("Hello") // yield() causes coroutine to produce value "Hello" for consumer
// and kotlincoro function gets suspended till consumer invokes
package generator
import java.io.File
fun canHandle(func: () -> Boolean): Boolean {
return func()
}
fun firstHandler(successor: Generator<String, String>? = null) = generate<String, String>{
package generator
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
/*
ES6-style generator that can send values between coroutine and outer code in both ways.
Note that in ES6-generators the first invocation of `next()` goes not accept a parameter, but
just starts a coroutine until a subsequent `yield`, so to adopt it for the type-safe interface
we must declare `next` to be always invoked with a parameter and make our coroutine receive the first
fun generator() = generate<Int, String> {
var c = 1
while (true) {
val op = yield(c)
when (op) {
"inc" -> c += 1
"mult" -> c *= 2
}
}
}
data class Customer(val name: String, val fidelityScore: Int)
data class LineItem(val productName: String, val qtyInKg: Int, val pricePerKg: Double) {
fun total(): Double {
return qtyInKg * pricePerKg
}
}
class Order(val customer: Customer, val cart: List<LineItem>, val promo: Promotion? = null) {
data class Customer(val name: String, val fidelityScore: Int)
data class LineItem(val productName: String, val qtyInKg: Int, val pricePerKg: Double) {
fun total(): Double {
return qtyInKg * pricePerKg
}
}
class Order(val customer: Customer, val cart: List<LineItem>, val promo: ((Order) -> Double)? = null) {
" vim-bootstrap
"*****************************************************************************
"" Vim-PLug core
"*****************************************************************************
let vimplug_exists=expand('~/.vim/autoload/plug.vim')
let g:vim_bootstrap_langs = "c"
let g:vim_bootstrap_editor = "vim" " nvim or vim
# Collection of useful python decorators
# Taken from https://eli.thegreenplace.net/2012/08/22/easy-tracing-of-nested-function-calls-in-python
# Easy tracing of nested function calls in Python
import sys
from functools import wraps
class TraceCalls(object):
""" Use as a decorator on functions that should be traced. Several
functions can be decorated - they will all be indented according