This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private sealed class Event { | |
data class TodoCheckedEvent(val id: Long, val completed: Boolean) : Event() | |
data class NewTodoEvent(val text: String) : Event() | |
data class DbUpdateEvent(val todos: List<TodoEntity>) : Event() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun reducer(state: State, event: Event): State = when (event) { | |
is Event.TodoCheckedEvent -> { | |
val todos = state.todos.map { todo -> | |
if (todo.id == event.id) todo.copy(completed = event.completed) | |
else todo | |
} | |
state.copy(todos = todos) | |
} | |
is Event.DbUpdateEvent -> state.copy(todos = event.todos) | |
is Event.NewTodoEvent -> state.copy( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val addNewTodoEffect = Transformer<State, Event, Event> { upstream -> | |
upstream.ofEventType(Event.NewTodoEvent::class) | |
.observeOn(Schedulers.io()) | |
.switchMap { (_, _, event) -> | |
db.todoDao().add( | |
TodoEntity( | |
id = 0, | |
text = event.text, | |
completed = false | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias ViewState = List<TodoViewData> | |
data class ViewStateEvent(val viewState: ViewState) : Event() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val viewStateEffect = Transformer<State, Event, Event.ViewStateEvent> { upstream -> | |
upstream.distinctUntilChanged { old, new -> old.second == new.second } | |
.map { (_, state, _) -> | |
val viewState = state.todos.map { | |
TodoViewData(it.id, it.text, it.completed) | |
} | |
.sortedBy { it.completed } | |
Event.ViewStateEvent(viewState) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val eventsFromView = viewEvents.map { viewEvent -> | |
when (viewEvent) { | |
is SampleViewEvent.TodoCheckedViewEvent -> | |
Event.TodoCheckedEvent(viewEvent.id, viewEvent.isChecked) | |
is SampleViewEvent.TodoAddedViewEvent -> | |
Event.NewTodoEvent(viewEvent.text) | |
} | |
} | |
val dbEvents = db.todoDao().getAll().toObservable().map(::DbUpdateEvent) | |
val externalEvents = Observable.merge(eventsFromView, dbEvents) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.charlag.memoize | |
fun <A, E> ((A) -> E).memoize(): ((A) -> E) { | |
var arg: A? = null | |
var result: E? = null | |
return { a -> | |
if (a != arg) { | |
arg = a | |
result = this(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo 'http://kernel.ubuntu.com/~kernel-ppa/mainline/?C=N;O=D' | |
#read -p 'Version to install: ' KERNEL_VERSION | |
KERNEL_VERSION="4.19.9" | |
KDIR="kernel_$KERNEL_VERSION" | |
gio trash -f $KDIR | |
mkdir $KDIR | |
wget "http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNEL_VERSION}/CHECKSUMS" -O $KDIR/CHECKSUMS -nv | |
HEADERS_ALL_LINE=$(grep -i -m 1 "linux-headers-.*_all.deb" $KDIR/CHECKSUMS) | |
HEADERS_ALL_ARR=($HEADERS_ALL_LINE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let's say this is a top of my timeline: | |
"100883628340642811", | |
"100883628339152625", | |
"100883628129621553", | |
"100883627886489576", | |
"100883626425518196", | |
"100883626407487034", | |
"100883626392971820", | |
"100883626164206546", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun gh-md () | |
"Copy Replace current file's ORG contents replaced | |
with Github-flavoured ones. Works quite poorly for now." | |
(interactive) | |
(let ((real-buffer (current-buffer))) | |
(with-temp-buffer | |
(let ((temp-buffer (current-buffer))) | |
(with-current-buffer real-buffer | |
(copy-to-buffer temp-buffer (point-min) (point-max)) | |
)) |