Skip to content

Instantly share code, notes, and snippets.

View passsy's full-sized avatar

Pascal Welsch passsy

View GitHub Profile
@passsy
passsy / LastCall.java
Last active February 13, 2017 14:35 — forked from sockeqwe/LastCall.java
Mockito verification of the last call on a method (targeting org.mockito:mockito-core:2.7.5)
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 / TestParcelable.java
Last active April 3, 2017 17:02
How to test a parcelable in androidTest
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 / make_archive.sh
Created April 13, 2017 14:51
Create an archive of our source code without git history (including all submodules)
#!/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 / 1-global_build.gradle
Last active September 22, 2017 14:09
include git-versioner into your project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@passsy
passsy / OperatorSemaphore.java
Created April 28, 2015 14:33
A Presenter when using RxAndroid which delays delivering to the View when the View isn't ready
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Konstantin Mikheev sirstripy-at-gmail-com
*
* 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
@passsy
passsy / RxExt.kt
Created June 6, 2018 16:01
Allow Rx Single to map to nullable values by converting to Maybe. #kotlin
/**
* 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)
}
public class HelloWorldActivity
extends TiActivity<HelloWorldPresenter, HelloWorldView>
implements HelloWorldView {
private TextView mOutput;
@NonNull
@Override
public HelloWorldPresenter providePresenter() {
return new HelloWorldPresenter();
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 / main.dart
Last active May 13, 2019 15:23
Missing compile time check
class Apple {}
class Banana {}
List<Apple> bag([List<Apple> apples]) => apples ?? <Banana>[];
void main() {
// ok
final bag1 = bag([Apple()]);
print(bag1);
@passsy
passsy / main.dart
Created July 20, 2019 13:49
Flutter ListView with fixed header expanding below system navigation
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);