Skip to content

Instantly share code, notes, and snippets.

View passsy's full-sized avatar

Pascal Welsch passsy

View GitHub Profile
@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 / build.gradle
Last active November 14, 2022 15:43
lazy jake wharton versioning
def versionMajor = 3
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
android {
defaultConfig {
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
@passsy
passsy / build.gradle
Last active June 6, 2016 12:44
lazy versionCode with git versioner
// Optional: configure the versioner (before applying the script)
/* ext.gitVersioner = [
defaultBranch : "develop", // default "master"
yearFactor : 1200, // default "1000", increasing every 8.57h
snapshotEnabled : false, // default false, the "-SNAPSHOT" postfix
localChangesCountEnabled: false // default false, the (<commitCount>) before -SNAPSHOT
] */
apply from: 'https://raw.githubusercontent.com/passsy/gradle-GitVersioner/master/git-versioner.gradle'
android {
@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
public class HelloWorldActivity
extends TiActivity<HelloWorldPresenter, HelloWorldView>
implements HelloWorldView {
private TextView mOutput;
@NonNull
@Override
public HelloWorldPresenter providePresenter() {
return new HelloWorldPresenter();
@passsy
passsy / ViewModelExample.kt
Last active September 14, 2016 13:43
VPVM Example of a ViewModel which can be used inside a ThirtyInch TiPresenter. This is built with Kotlin and Rx. While you may not use those technologies in your app you get the idea
private class ViewModel {
private var changing = PublishSubject.create<Unit>()
fun observe(): Observable<ViewModel> {
return Observable.just(this).mergeWith(changing.map { this })
}
var results: List<SearchResult> by onChangeNotifySubject(emptyList(), changing,
{ p, o, newValue -> if (newValue.isEmpty()) selectedResult = null })
@passsy
passsy / _fabricGradleFix.md
Last active January 26, 2017 10:33
Fabric gradle plugin bug fix

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.

@passsy
passsy / LastCall.java
Created December 15, 2016 14:48
Mockito verification of the last call on a method
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 / build.gradle
Created January 27, 2017 19:01
ThirtyInch includeBuild
dependencies {
compile "ThirtyInch:thirtyinch"
compile "ThirtyInch:thirtyinch-rx"
compile "ThirtyInch:thirtyinch-plugin"
testCompile "ThirtyInch:thirtyinch-test"
}
@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;