Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / EditText.xml
Created Apr 23, 2015
Android - EditText disabled but clickable
View EditText.xml
<EditText ...
android:clickable="true"
android:cursorVisible="false"
android:focusable="false"/>
@danielgomezrico
danielgomezrico / update_list.dart
Created Mar 5, 2021
Example showing how to update a list
View update_list.dart
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 Feb 5, 2021
Dart - simple yield and yield* example
View yield.dart
Stream<String> otherNumbers() {
return Stream.fromIterable(["2", "3"]);
}
Stream<String> allNumbers() async* {
yield "1";
yield* otherNumbers();
}
@danielgomezrico
danielgomezrico / Checkbox.xml
Created Sep 14, 2015
Android - Checkbox as star/favorite view.
View Checkbox.xml
<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 / DistanceCalculator.java
Last active Jan 6, 2021
Java / Android - calculate the distance between two coordinates with great circle formula.
View DistanceCalculator.java
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
/**
* Calculate distance between coordinates.
*/
public class DistanceCalculator {
static double PI_RAD = Math.PI / 180.0;
@danielgomezrico
danielgomezrico / check-format.sh
Created Dec 27, 2020
Flutter - Check code format and fail if does not work, useful for CI flows
View check-format.sh
#!/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/)
View String+IsBlank
extension String {
var isBlank: Bool {
get {
let trimmed = stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
return trimmed.isEmpty
}
}
@danielgomezrico
danielgomezrico / provider_generic_extensions.dart
Last active Nov 28, 2020
Dart/Flutter - Extensions to emit ChangeNotifier changes as a Stream, very useful for unit testing
View provider_generic_extensions.dart
/// 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 / jacoco.gradle
Last active Oct 5, 2020
Gradle - jacoco gradle file that is setup to run tests and create test coverage reports for Android (junit tests or connectedTests...). apply to your project and check "reporting" in gradle tasks. Thanks to https://github.com/artem-zinnatullin/qualitymatters for it.
View jacoco.gradle
project.afterEvaluate {
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
// When no product flavors defined, use empty
if (!productFlavors) productFlavors.add('')
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
@danielgomezrico
danielgomezrico / clean_branches.sh
Last active Aug 31, 2020
Bash / Git - remove local and remote branches for repo cleanup
View clean_branches.sh
#!/usr/bin/env sh
#
# Remove from local and remotes the branches inside
# BRANCHES array
#
BRANCHES=(
branch_1
feature/branch_2
feature/other_thing