Skip to content

Instantly share code, notes, and snippets.

View dumazy's full-sized avatar

Fré Dumazy dumazy

View GitHub Profile
@dumazy
dumazy / AndroidLogKotlin.xml
Created September 4, 2017 18:53
Android Studio Live Templates for Log statements in Kotlin
<templateSet group="AndroidLogKotlin">
<template name="logd" value="android.util.Log.d(&quot;$CLASS_NAME$&quot;, &quot;$METHOD_NAME$ (line $LINE$): $MESSAGE$&quot;)$END$" description="Log.d statement" toReformat="false" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="groovyScript(&quot;if(_1.length() &gt; 23) { return _1.substring(0, 23)} else { return _1}&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="LINE" expression="lineNumber()" defaultValue="" alwaysStopAt="false" />
<variable name="MESSAGE" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
@dumazy
dumazy / axios.refresh_token.js
Created January 2, 2019 12:58 — forked from Godofbrowser/axios.refresh_token.1.js
Axios interceptor for refresh token when you have multiple parallel requests
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);
@dumazy
dumazy / gist:b5f64d4c544489569b65be7a30990983
Created October 31, 2020 09:49
Flutter sandbox script
#!/bin/bash
# Absolute path of the Flutter sandbox project
sandbox_path="/Users/fre.dumazy/Developer/Playground/flutter_sandbox"
# Name of Android emulator to open.
# Check with `emulator -list-avds`
avd_name="Pixel_4_API_30"
main() {
processOptions "$@"
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 500.0,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: ['English', 'Russian', 'Spanish']
@dumazy
dumazy / main.dart
Created August 3, 2021 06:08
Complex json display flutter
import 'package:flutter/material.dart';
import 'dart:convert';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@dumazy
dumazy / main.dart
Created November 26, 2023 12:24
ColorScheme.formSeed
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@dumazy
dumazy / change_notifier_listener_example.dart
Last active March 6, 2024 18:32
A utility to wait for notifyListeners to be called
// When there are external events triggering notifyListeners() in a ChangeNotifier,
// how can we easily test them? Not sure if something like this `ChangeNotifierListener` below
// is a valid approach, or if there are easy ways to test `ChangeNotifier` in a unit test, without a widget test.
// Just for sake of the example
class MyViewModel with ChangeNotifier {
MyViewModel(Stream<Object> eventStream) {
eventStream.listen((event) {
_counter++;
@dumazy
dumazy / dart-fix-all-separately.sh
Created June 5, 2024 09:56
Apply all 'dart fix' separately
#!/bin/bash
# This script applies Dart fixes to a project and commits the changes for each fix separately.
# It uses the `dart fix --dry-run` command to find the fixes that can be applied.
# For each fix, it applies the fix and commits the changes with a message indicating the fix code.
checkDart() {
if ! command -v dart &> /dev/null
then
echo "Dart could not be found. Please install Dart first."
@dumazy
dumazy / main.dart
Last active June 6, 2024 19:57
Animated border in a heart shape using PathMetric.getTangentForOffset
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:ui' as ui;
import 'dart:ui';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
@dumazy
dumazy / main.dart
Created August 27, 2024 17:38
ScaffoldMessenger theming issue
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
void showThemedSnackBar() {
final messenger = _scaffoldMessengerKey.currentState!;