Skip to content

Instantly share code, notes, and snippets.

View danielgomezrico's full-sized avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / pubspec.yaml
Created May 2, 2024 21:20
Flutter - Built Value - Build Runner: script to update pubscpec with the files to autogenerate
targets:
$default:
builders:
built_value_generator:built_value:generate_for:
generate_for:
- HERE
@danielgomezrico
danielgomezrico / result.dart
Created March 20, 2024 19:59
Example - Study: check if typedef works for type checks
import 'dart:async';
typedef FutureResult<T> = Future<Result<T>>;
typedef FutureOrResult<T> = FutureOr<Result<T>>;
typedef ConcatResult<F, S> = ({F first, S second});
abstract class Result<T> {
const Result();
@danielgomezrico
danielgomezrico / Function.java
Created May 9, 2015 16:05
Android - check if running on main thread
public boolean runningOnMainThread() {
return Looper.getMainLooper().getThread() == Thread.currentThread();
}
@danielgomezrico
danielgomezrico / readme.md
Created January 5, 2024 17:21
i18n performance test using i18n.Of, temporal variables and i18n.current

Results are:

With Current

  • direclty access to i18n(RunTime): 55185442.5 us.
  • indireclty access to i18n(RunTime): 55758307.0 us.
  • indireclty outside access to i18n(RunTime): 56177293.5 us.

With BuildContext

  • direclty access to i18n(RunTime): 92459941.0 us.
  • indireclty access to i18n(RunTime): 83667963.5 us.
@danielgomezrico
danielgomezrico / result_monad_2.dart
Last active December 15, 2023 15:06
Result Monad Example 2
///
/// The Result Monad
///
abstract class Result<T> {
bool isSuccess() {
return this is Success;
}
Success<T> asSuccess() {
return this as Success<T>;
@danielgomezrico
danielgomezrico / Manifest.xml
Created December 13, 2023 21:47
Flutter · Dart: web server to start a local webserver
<!-- Attribute to add on android -->
<app
....
android:usesCleartextTraffic="true">
...
</app>
@danielgomezrico
danielgomezrico / Checkbox.xml
Created September 14, 2015 03:21
Android - Checkbox as star/favorite view.
<CheckBox
android:id="@+id/item_card_check_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="@dimen/activity_margin"
style="?android:attr/starStyle"/>
@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 / 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 / AndroidManifest.xml
Last active March 26, 2023 11:57 — forked from xrigau/AndroidManifest.xml
Android - AndroidJUnitRunner that disable animations, disable screen lock and wake processor all the time to avoid Tests to fail because of test device setup. Note that my test buildType is mock to have a manifest just for tests (dont want to ship an app with SET_ANIMATION_SCALE permissions...).
<?xml version="1.0" encoding="utf-8"?>
<!-- This file should be outside of release manifest (in this case app/src/mock/Manifest.xml -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tests">
<!-- For espresso testing purposes, this is removed in live builds, but not in dev builds -->
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />