Skip to content

Instantly share code, notes, and snippets.

View danielgomezrico's full-sized avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / result_monad_1.dart
Last active February 9, 2022 12:40
Result Monad as example
///
/// The Result Monad
///
abstract class Result<T> {
bool isSuccess() {
return this is Success;
}
Success<T> asSuccess() {
@danielgomezrico
danielgomezrico / Dangerfile.rb
Created January 8, 2022 18:10
DangerFile - Danger System - script to check conventional commits titles and size of the PR
# https://www.regextester.com/109925
CONVENTIONS_URL = "your link"
def validate_title_format
def valid_title_format?(title)
conventional_commit_regex = /^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?: .*$/
result = title =~ conventional_commit_regex
result != nil
end
@danielgomezrico
danielgomezrico / markdown-details-collapsible.md
Created August 12, 2021 16:12 — forked from pierrejoubert73/markdown-details-collapsible.md
How to add a collapsible section in markdown.

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets
@danielgomezrico
danielgomezrico / update_list.dart
Created March 5, 2021 18:26
Example showing how to update a list
class Person {
Person(this.name);
final String name;
String toString() => name;
}
void main() {
final items = [Person("juan"), Person("pedro"), Person("coso")];
@danielgomezrico
danielgomezrico / yield.dart
Created February 5, 2021 19:56
Dart - simple yield and yield* example
Stream<String> otherNumbers() {
return Stream.fromIterable(["2", "3"]);
}
Stream<String> allNumbers() async* {
yield "1";
yield* otherNumbers();
}
@danielgomezrico
danielgomezrico / check-format.sh
Created December 27, 2020 16:36
Flutter - Check code format and fail if does not work, useful for CI flows
#!/usr/bin/env bash
#
# Runs dartfmt from dart_style to check if all of the source files are well formatted
# Requires you to have dartfmt already in your path with 'pub global activate dart_style'
#
echo "-> Running 'flutter format' to check project dart style 🤓"
RESULT=$(flutter format -n lib/main.dart lib/src/ test/)
@danielgomezrico
danielgomezrico / provider_generic_extensions.dart
Last active October 19, 2023 16:07
Dart/Flutter - Extensions to emit ChangeNotifier changes as a Stream, very useful for unit testing
/// Function to get the changed value everytime
typedef GetChangeFunction<T> = T Function();
extension AsStream<T> on ChangeNotifier {
Stream<T> statusAsStream(GetChangeFunction<T> getChange) {
final controller = StreamController<T>();
// Redirect status changes into the Stream
@danielgomezrico
danielgomezrico / example.dart
Last active August 15, 2020 22:14
Flutter - Android - extensions to mock more easy on testing with mockito
// The abstractions
abstract class Result<T> {
}
class Success<T> extends Result<T> {
final T body;
Success(this.body);
}
@danielgomezrico
danielgomezrico / generics_failure.dart
Created August 15, 2020 16:13
Generics failure example with dart
abstract class Result<T> { }
class Success<T> extends Result<T> {
final T body;
Success(this.body);
}
class Failure<T> extends Result<T> {
@danielgomezrico
danielgomezrico / jacoco.gradle
Last active February 15, 2023 09:41
Jacoco setup to merge coverage for android when you run unit tests + integration tests and get a mixed result
// Merge of
// https://github.com/mgouline/android-samples/blob/master/jacoco/app/build.gradle
// and https://github.com/pushtorefresh/storio/blob/master/gradle/jacoco-android.gradle
// Requires Jacoco plugin in build classpath.
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.3"
}