Skip to content

Instantly share code, notes, and snippets.

Avatar

Pascal Welsch passsy

View GitHub Profile
View RxDelay.kt
object Rx {
fun <T> delayFlowable(delay: Long, timeUnit: TimeUnit, scheduler: Scheduler = Schedulers.computation(),
block: () -> Flowable<T>): Flowable<T> {
return Completable.timer(delay, timeUnit, scheduler).andThen(Flowable.defer { block() })
}
fun <T> delayObservable(delay: Long, timeUnit: TimeUnit, scheduler: Scheduler = Schedulers.computation(),
block: () -> Observable<T>): Observable<T> {
return Completable.timer(delay, timeUnit, scheduler).andThen(Observable.defer { block() })
}
@passsy
passsy / RxExt.kt
Created Jun 6, 2018
Allow Rx Single to map to nullable values by converting to Maybe. #kotlin
View RxExt.kt
/**
* Maps the [Single] value [T] to a nullable type [R?] which will become [Maybe.empty] when `R == null`,
* otherwise [Maybe.just]
*/
inline fun <T, R> Single<T>.mapNullable(crossinline mapper: (T) -> R?): Maybe<R> = this.flatMapMaybe {
val result = mapper(it)
if (result == null) Maybe.empty() else Maybe.just(result)
}
@passsy
passsy / Locale.kt
Last active May 28, 2020
Allows easy iteration about all available locales. Kotlin Collection implementation for LocaleList which doesn't implement Collection<Locale> itself.
View Locale.kt
package com.pascalwelsch.android.util
import android.content.Context
import androidx.core.os.ConfigurationCompat
import androidx.core.os.LocaleListCompat
import java.util.Locale
/**
* Returns an [Iterable] for the languages of the user, sorted by priority. First choice first.
*/
@passsy
passsy / make_archive.sh
Created Apr 13, 2017
Create an archive of our source code without git history (including all submodules)
View make_archive.sh
#!/bin/sh
# Check if 7zip is installed and install it if not
hash 7z 2>/dev/null || {
echo >&2 "7z is required to be installed";
echo "I will install it for you";
brew install p7zip;
}
# Read the commit sha
@passsy
passsy / TestParcelable.java
Last active Apr 3, 2017
How to test a parcelable in androidTest
View TestParcelable.java
public class ParcelableTest extends AndroidTestCase {
/**
* Parcels the given Parcelable, unparcels it and returns the unparceled value
*
* @param value the Parcelable to operate on
*/
public static Parcelable parcelAndUnparcel(Parcelable value) {
Parcel parcel = Parcel.obtain();
value.writeToParcel(parcel, 0);
@passsy
passsy / KIntent.kt
Last active Sep 29, 2020
Kotlin extension functions to start a generic Activity
View KIntent.kt
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities
@passsy
passsy / LastCall.java
Last active Feb 13, 2017 — forked from sockeqwe/LastCall.java
Mockito verification of the last call on a method (targeting org.mockito:mockito-core:2.7.5)
View LastCall.java
package com.pascalwelsch.mockito;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.exceptions.verification.ArgumentsAreDifferent;
import org.mockito.internal.debugging.LocationImpl;
import org.mockito.internal.junit.JUnitTool;
import org.mockito.internal.reporting.SmartPrinter;
import org.mockito.internal.verification.VerificationModeFactory;
import org.mockito.internal.verification.api.VerificationData;
import org.mockito.internal.verification.argumentmatching.ArgumentMatchingTool;
@passsy
passsy / build.gradle
Created Jan 27, 2017
ThirtyInch includeBuild
View build.gradle
dependencies {
compile "ThirtyInch:thirtyinch"
compile "ThirtyInch:thirtyinch-rx"
compile "ThirtyInch:thirtyinch-plugin"
testCompile "ThirtyInch:thirtyinch-test"
}
@passsy
passsy / LastCall.java
Created Dec 15, 2016
Mockito verification of the last call on a method
View LastCall.java
package com.pascalwelsch.mockito;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.exceptions.verification.ArgumentsAreDifferent;
import org.mockito.internal.debugging.LocationImpl;
import org.mockito.internal.invocation.InvocationMatcher;
import org.mockito.internal.junit.JUnitTool;
import org.mockito.internal.reporting.SmartPrinter;
import org.mockito.internal.verification.api.VerificationData;
import org.mockito.internal.verification.argumentmatching.ArgumentMatchingTool;
@passsy
passsy / _fabricGradleFix.md
Last active Jan 26, 2017
Fabric gradle plugin bug fix
View _fabricGradleFix.md

The fabric gradle plugin io.fabric.tools:gradle:1.21.7 generates the crashlytics xml containing the project ID over and over again even when the file exists. The regeneration of the generated resource forces the generateDevDebugResValues task to perform again. It can't skip with the state UP-TO-DATE.

The plugin should check if the file with the correct content already exists before it gets changed.

Even worse when the firebase com.google.gms.google-services is included as dependency. It also checks for changed resources and starts all over again.