Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / pre-commit.sh
Created January 20, 2023 16:32
Git - Hook - Pre Commit - Flutter: format files before they are commited
View pre-commit.sh
#!/bin/sh
#
# Autoformat all modified files before commit
#
function format_if_required {
FILES=$1
flutter format $FILES | grep -Ev '^(Unchanged)'
@danielgomezrico
danielgomezrico / pre-commit.sh
Created December 14, 2022 17:22
Git - hook - pre-commit: for flutter/dart format each modified file ultra fast before each commit
View pre-commit.sh
#!/bin/sh
#
# Autoformat all modified files before commit
#
function format_if_required {
FILES=$1
flutter format $FILES | grep -Ev '^(Unchanged)'
@danielgomezrico
danielgomezrico / build.dart
Last active August 24, 2022 20:22
Dart - how to create a url with query params with language features
View build.dart
// Use language features to build the url
String buildUrlWithQueryParams(String url, Map<String, dynamic> queryParams) {
final uri = Uri.parse(url);
final fullUri = uri.replace(
queryParameters: {
...uri.queryParameters,
...queryParams,
},
);
@danielgomezrico
danielgomezrico / comment_with_pr_number.yml
Created July 15, 2022 19:57
Github Action - Comment on PR using the PR number
View comment_with_pr_number.yml
name: PR Commenter
on:
pull_request:
types: [opened, reopened]
jobs:
comment:
runs-on: ubuntu-latest
steps:
@danielgomezrico
danielgomezrico / await.dart
Last active March 18, 2022 22:01
List.await • dart: example to see the order of the returned results
View await.dart
import 'dart:async';
Future main() async {
print('start');
final li = await Future.wait([fetch(4), fetch(6)]);
print('results: ${li[0]} ${li[1]}'); // results: 4 2
final li2 = await Future.wait([fetch(6), fetch(3)]);
print('results 2: ${li2[0]} ${li2[1]}'); // results: 6 3
@danielgomezrico
danielgomezrico / call_example.dart
Created February 14, 2022 18:05
UseCase / Interactor - naming convention to use with use cases
View call_example.dart
class UpdateUserInteractor {
Future<void> call(String name) async {
print("done $name");
return;
}
}
void main() async {
final updateUser = UpdateUserInteractor();
await updateUser('Dan');
@danielgomezrico
danielgomezrico / result_monad_2
Created February 9, 2022 12:41
Result Monad Example 2
View result_monad_2
///
/// The Result Monad
///
abstract class Result<T> {
bool isSuccess() {
return this is Success;
}
Success<T> asSuccess() {
return this as Success<T>;
@danielgomezrico
danielgomezrico / result_monad_1.dart
Last active February 9, 2022 12:40
Result Monad as example
View result_monad_1.dart
///
/// 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
View Dangerfile.rb
# 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.
View markdown-details-collapsible.md

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets