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
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 / deep_pick.dart
Created September 27, 2019 15:03
Sample how to use deep_pick to parse json in 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 / lcd.md
Created December 12, 2019 12:32
LCD Flutter Dojo

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 / main.dart
Created December 29, 2019 20:01
Comparison between ?? and a orDefault method
void main() {
final String name = "Adam";
print("=== ?? ===");
// does not execute defaultValue()
print(name ?? defaultValue());
print("=== orDefault ===");
// executes defaultValue()
print(name.orDefault(defaultValue()));
@passsy
passsy / run_coverage.sh
Created February 3, 2020 01:05
Run dart code coverage
#!/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 \

Interactive CLI in Dart

Screen-Recording-2020-03-03-22-55-27

Example how to build a interactive CLI application in Dart

@passsy
passsy / main.dart
Created April 23, 2020 19:20
Type switch case
void main() {
final Object something = TypeA();
something.matchTypes({
TypeA : () => print("found A"),
TypeB : () => print("found B"),
});
}
@passsy
passsy / const_uri.dart
Last active March 16, 2021 00:49
const implemenation of dart:core Uri
// @dart=2.12
/// A const implementation of Uri which crashes at first access in case the uri is invalid
class ConstUri implements Uri {
/// Caches the static parsed uri
///
/// The parsed uri can't be a mutable member field because that's not allowed for const classes
static final _cache = <String, Uri>{};
const ConstUri(String uri) : _uri = uri;
@passsy
passsy / main.dart
Created June 17, 2020 10:29
wrap_content match_parent in Flutter
import 'package:flutter/material.dart';
Future<void> main() async {
runApp(Builder(
builder: (context) => const MyApp(),
));
}
class MyApp extends StatelessWidget {
const MyApp({
@passsy
passsy / ArrayAdapter.java
Last active August 15, 2021 10:05
ArrayAdapter for RecyclerView
package com.pascalwelsch.utils;
import android.support.annotation.Nullable;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;