Skip to content

Instantly share code, notes, and snippets.

Avatar

Pascal Welsch passsy

View GitHub Profile
@passsy
passsy / run_coverage.sh
Created Feb 3, 2020
Run dart code coverage
View run_coverage.sh
#!/bin/sh
# Usage: ./tool/run_coverage.sh test/all_tests.dart
(pub global list | grep coverage) || {
# install coverage when not found
pub global activate coverage
}
pub global run coverage:collect_coverage \
@passsy
passsy / A_README.md
Last active Jan 17, 2020
Android Studio Light Theme
View A_README.md

Colorful Java (and Kotlin) Android Studio Theme

This Android Studio Theme (or IntelliJ in general) is based on many IDEs.

Previews

@passsy
passsy / main.dart
Created Dec 29, 2019
Comparison between ?? and a orDefault method
View main.dart
void main() {
final String name = "Adam";
print("=== ?? ===");
// does not execute defaultValue()
print(name ?? defaultValue());
print("=== orDefault ===");
// executes defaultValue()
print(name.orDefault(defaultValue()));
@passsy
passsy / lcd.md
Created Dec 12, 2019
LCD Flutter Dojo
View lcd.md

Number to LCD Kata

Kotlin coding dojo no. 8: convert a given integer number to a LCD style number, see Part 1 of NumberToLCDKata

    0123456789
         
         
         |
         V
@passsy
passsy / deep_pick.dart
Created Sep 27, 2019
Sample how to use deep_pick to parse json in dart
View deep_pick.dart
import 'dart:convert';
import 'package:deep_pick/deep_pick.dart';
import 'package:http/http.dart' as http;
Future<void> main() async {
/// Request data from a json API
final response = await http.get("https://pokeapi.co/api/v2/pokemon/1");
final json = jsonDecode(response.body);
@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 / main.dart
Created Jul 20, 2019
Flutter ListView with fixed header expanding below system navigation
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
@passsy
passsy / main.dart
Last active May 13, 2019
Missing compile time check
View main.dart
class Apple {}
class Banana {}
List<Apple> bag([List<Apple> apples]) => apples ?? <Banana>[];
void main() {
// ok
final bag1 = bag([Apple()]);
print(bag1);
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() })
}
View HelloWorldActivity.java
public class HelloWorldActivity
extends TiActivity<HelloWorldPresenter, HelloWorldView>
implements HelloWorldView {
private TextView mOutput;
@NonNull
@Override
public HelloWorldPresenter providePresenter() {
return new HelloWorldPresenter();