Skip to content

Instantly share code, notes, and snippets.

Avatar

Vitaliy ultraon

View GitHub Profile
View tuples.kt
fun main(args: Array<String>) {
println("a" to "b")
println("a" to "b" tre "c")
println("a" to "b" tre "c" fo "d")
println("a" to "b" tre "c" fo "d" fi "e")
println("a" to "b" tre "c" fo "d" fi "e" sik "f")
println("a" to "b" tre "c" fo "d" fi "e" sik "f" seva "g")
}
infix fun <A, B, C> Pair<A, B>.tre(c: C) = Triple(first, second, c)
@hrach
hrach / channel.kt
Last active Apr 8, 2020
Kotlin Channels Debounce & Throttle
View channel.kt
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.channels.produce
import kotlin.coroutines.experimental.CoroutineContext
fun <E> ReceiveChannel<E>.debounce(
wait: Long = 50,
context: CoroutineContext = DefaultDispatcher
): ReceiveChannel<E> = produce(context) {
@imminent
imminent / ClickActors.kt
Created Nov 25, 2017
Kotlin actor extensions for Android listeners
View ClickActors.kt
/**
* MIT License
*
* Copyright (c) 2017 Dandré Allison
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
View Example.kt
// https://akarnokd.blogspot.ru/2017/09/rxjava-vs-kotlin-coroutines-quick-look.html
import kotlinx.coroutines.experimental.*
suspend fun f1(i: Int): Int {
Thread.sleep(if (i != 2) 2000L else 200L)
return 1
}
suspend fun f2(i: Int): Int {
Thread.sleep(if (i != 2) 2000L else 200L)
@koral--
koral-- / build.gradle
Last active Dec 12, 2017
testApt to testAnnotationProcessor migration, workaround for issue: https://code.google.com/p/android/issues/detail?id=224272
View build.gradle
android.applicationVariants.all {
def aptOutputDir = new File(buildDir, "generated/source/apt/${it.unitTestVariant.dirName}")
it.unitTestVariant.addJavaSourceFoldersToModel(aptOutputDir)
}
@gtomek
gtomek / IoUtilsWithOkIo.java
Created Feb 10, 2016
Read files with Okio
View IoUtilsWithOkIo.java
/**
* Utils for I/O operations.
* <p/>
* Created by Tomek on 09/06/15.
*/
public class IoUtils {
/**
* Reads file and returns a String.
*
@vaughandroid
vaughandroid / ModuleOverride.java
Last active Mar 11, 2020
Not quite the easiest way to override Dagger 2 modules for unit tests...
View ModuleOverride.java
@Component(modules=MyModule.class)
@ApplicationScope
public interface MyComponent {
void inject(MyApplication application);
}
@Module
public class MyModule {
@Provides @ApplicationScope
@frogermcs
frogermcs / ActivityScope.java
Last active Apr 23, 2020
Sources for blog post "Dependency injection with Dagger 2 - the API"
View ActivityScope.java
@Scope
public @interface ActivityScope {
}
@daverix
daverix / Testing.java
Last active Dec 30, 2017
Dagger2 sub components example
View Testing.java
package com.example;
import javax.inject.Scope;
import javax.inject.Singleton;
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
You can’t perform that action at this time.