Skip to content

Instantly share code, notes, and snippets.

View nsk-mironov's full-sized avatar

Vladimir Mironov nsk-mironov

  • Lisbon, Portugal
View GitHub Profile
public Observable<Response> upload(final Image image) {
// create new ArrayList in case if image.getChunks() returns immutable collection
final List<Chunk> chunks = new ArrayList<Chunk>(image.getChunks());
if (chunks.isEmpty()) {
return Observable.empty();
}
if (chunks.size() == 1) {
return api.upload(chunks.get(0));
final Observable<MyDatum> observable = Observable.interval(10, TimeUnit.SECONDS).flatMap(new Func1<Long, Observable<MyDatum>>() {
@Override
public Observable<MyDatum> call(final Long counter) {
return db.select("SELECT f1,f2 FROM mydata")
.autoMap(MyDatum.class)
.doOnNext(new Action1<MyDatum>() {
@Override
public void call(final MyDatum value) {
state.add(value);
}
public class Main {
public static void main(String[] args) {
ContentManager cm = new ContentManager();
Observable
.from(cm.getPermalinks(10))
.flatMap(permalink -> Observable.zip(
Observable.<Content>create(subscriber -> cm.getDataByPermalink(permalink, new SubscribingRestCallback(subscriber))),
Observable.<Content>create(subscriber -> cm.getStreamByPermalink(permalink, new SubscribingRestCallback(subscriber))),
(dataContent, streamUrlContent) -> {
public class Main {
public static void main(final String[] args) throws Exception {
Observable.from(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12))
.groupBy(item -> item % 4)
.flatMap(Observable::toList)
.filter(integers -> integers.size() > 2)
.toList()
.subscribe(result -> {
System.out.printf("%d results %s%n", result.size(), result);
});
@nsk-mironov
nsk-mironov / OperatorThrottleList.java
Last active August 29, 2015 14:26
OperatorThrottleList
public final class OperatorThrottleList<T> implements Operator<T, List<T>> {
private final Scheduler scheduler;
private final long interval;
public OperatorThrottleList(final long interval, final TimeUnit unit, final Scheduler scheduler) {
this.interval = unit.toMillis(interval);
this.scheduler = scheduler;
}
@Override
public class StackOverflow {
public static void main(String[] args) {
final Observable<Integer> firstObs = Observable.just(1, 2, 3, 4, 5);
final Observable<Integer> secondObs = Observable.just(2, 4, 6);
final Observable<Integer> result = secondObs.toList().flatMap(new Func1<List<Integer>, Observable<Integer>>() {
@Override
public Observable<Integer> call(final List<Integer> ignore) {
return firstObs.filter(new Func1<Integer, Boolean>() {
@Override
<T:Ljava/lang/Object;A:[TT;>(TA;I)TA;
final class com/github/vmironov/MainKt$main$first$1 extends kotlin/jvm/internal/FunctionReference implements kotlin/jvm/functions/Function2 {
// access flags 0x1041
public synthetic bridge invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
ALOAD 0
ALOAD 1
CHECKCAST com/github/vmironov/A
ALOAD 2
CHECKCAST java/lang/Number
INVOKEVIRTUAL java/lang/Number.intValue ()I
INVOKEVIRTUAL com/github/vmironov/MainKt$main$first$1.invoke (Lcom/github/vmironov/A;I)I
@nsk-mironov
nsk-mironov / AccountViewModel.kt
Created April 11, 2016 13:38
Databinding with DelegatedProperties
class AccountViewModel : ObservableModel by ObservableModelDelegate() {
@get:Bindable var name by property<CharSequence>("", BR.name)
@get:Bindable var authenticated by property(false, BR.authenticated)
@get:Bindable var avatar by property("", BR.avatar)
}
@nsk-mironov
nsk-mironov / Reflection.kt
Created March 13, 2016 16:50
Kotlin Metadata
package com.github.vmironov
import kotlin.reflect.jvm.internal.impl.serialization.ClassData
import kotlin.reflect.jvm.internal.impl.serialization.Flags
import kotlin.reflect.jvm.internal.impl.serialization.ProtoBuf
import kotlin.reflect.jvm.internal.impl.serialization.jvm.JvmProtoBufUtil
data class Foo(val foo: String)
data class Bar(val bar: String)