Skip to content

Instantly share code, notes, and snippets.

View aballano's full-sized avatar
🏠
Working from home

Alberto Ballano aballano

🏠
Working from home
View GitHub Profile
@aballano
aballano / remove_gradle_wrapper.sh
Created November 10, 2016 10:49
Removes all gradle wrapper folders except for the specified one.
cd ~/.gradle/wrapper/dists/
find . ! -name 'gradle-2.14.1-all' -type d -depth 1 -exec rm -f -r {} +
@Override public Observable showDeleteFailedWithRetry() {
Snackbar snackbar = Snackbar.make(rootView, "Can't delete chat", Snackbar.LENGTH_LONG);
Observable<Integer> observable = RxSnackbar.actionClicked(snackbar, "Retry"));
Observable<Integer> dismissObservable = RxSnackbar.dismisses(snackbar)
.filter(event -> event != Snackbar.Callback.DISMISS_EVENT_ACTION)
.flatMap(ignored -> Observable.error(new Throwable()));
snackbar.show();
return observable.mergeWith(dismissObservable);
}
@aballano
aballano / GenericExtensions.kt
Created March 12, 2017 16:57
Kotlin ternary operator
// Source: http://stackoverflow.com/a/39687177/616119
infix fun <T> Boolean.then(param: T): T? = if (this) param else null
// Usage:
println(condition then "true" ?: "false")
// Considerably inefficient implementation for test purposes
fun fib(k: Int): Long = when (k) {
0 -> 1
1 -> 1
else -> fib(k - 1) + fib(k - 2)
}
sealed class Option<out A> {
object None : Option<Nothing>()
data class Some<out A>(val value: A) : Option<A>()
inline fun <B> map(f: (A) -> B): Option<B> = when (this) {
is None -> this
is Some -> Some(f(value))
}
}
@aballano
aballano / require_dependency.py
Created April 15, 2017 00:40
Functions to install required dependencies for a python script.
#!/usr/bin/env python
import subprocess
import sys
def run_command(command):
return subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).strip()
Completable.complete()
.subscribe(
Action { throw exception },
Consumer { /* wont be called */ }
)
Observable.just(str)
.subscribe(
Consumer { throw exception },
fun <T> Single<T>.doCompletableOnSuccess(function: (T) -> Completable): Single<T> =
flatMap { function(it).andThen(Single.just(it)) }
fun <T> Maybe<T>.doCompletableOnSuccess(function: (T) -> Completable): Maybe<T> =
flatMap { function(it).andThen(Maybe.just(it)) }
import io.reactivex.CompletableObserver
import io.reactivex.MaybeObserver
import io.reactivex.Observer
import io.reactivex.SingleObserver
import io.reactivex.disposables.Disposable
import io.reactivex.exceptions.CompositeException
import io.reactivex.exceptions.Exceptions
import io.reactivex.functions.Action
import io.reactivex.functions.Consumer
import io.reactivex.internal.functions.Functions
@aballano
aballano / copyApkToCustomDir.gradle
Last active January 30, 2018 13:06
Trying to copy generated apk from build/outputs/apk/{variantname}/name.apk to build/outputs/apk/name.apk
def publish = project.tasks.create("copyApkToCustomDir")
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def task = project.tasks.create("copy${variant.name}Apk", Copy)
task.from(output.outputFile)
task.into("$project.buildDir/outputs/apk/")
println "Done"
task.dependsOn variant.assemble