Skip to content

Instantly share code, notes, and snippets.

Avatar

David Dikman ddikman

View GitHub Profile
@ddikman
ddikman / .gitlab-ci.yml
Created Sep 8, 2021
Gitlab CI for flutter build with caching packages folder
View .gitlab-ci.yml
cache:
paths:
- $CI_PROJECT_DIR/.pub-cache/
build:
image: greycastle/flutter:2.2.3
script:
- export PUB_CACHE=$CI_PROJECT_DIR/.pub-cache
- export PATH="$PATH":"$PUB_CACHE/bin"
- flutter pub get
@ddikman
ddikman / download.sh
Created Aug 25, 2021
Bash script to download a list of URLs
View download.sh
#!/bin/bash
# usage:
# chmod +x download.sh
# pbpaste | download.sh
# cat inputfile.txt | download.sh
# thanks to https://stackoverflow.com/a/7045517
while read -r full_url
@ddikman
ddikman / app_root.dart
Created Aug 16, 2021
Example of loading remote config, avoiding stale values during testing
View app_root.dart
_initRemoteConfig(ExperimentalMode experimentalMode) async {
final RemoteConfig remoteConfig = RemoteConfig.instance;
var cacheDuration = Duration(hours: 1);
// allows us to force update the cache even when we exit the experimental mode
if (experimentalMode.isExperimentalMode || experimentalMode.isConfigStale()) {
cacheDuration = Duration(seconds: 0);
}
experimentalMode.setConfigStale(false);
await remoteConfig.setConfigSettings(RemoteConfigSettings(
@ddikman
ddikman / experimental_switcher.dart
Created Aug 16, 2021
A wrapper widget to enable tapping to switch off or on an experimental mode setting
View experimental_switcher.dart
import 'package:flutter/material.dart';
import 'package:japanese_reading/settings_page/services/experimental_mode.dart';
class ExperimentalModeSwitcher extends StatefulWidget {
final Widget child;
final ExperimentalMode experimentalMode;
const ExperimentalModeSwitcher({Key key, @required this.child, @required this.experimentalMode}) : super(key: key);
@override
@ddikman
ddikman / experimental_mode.dart
Created Aug 16, 2021
Example of a service to help abstract the storage of experimental mode on local device
View experimental_mode.dart
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:japanese_reading/services/preferences.dart';
class ExperimentalMode {
static final cacheStaleKey = 'cache_stale';
static final experimentalModeKey = 'experimental_mode';
final FirebaseAnalytics analytics;
final Preferences preferences;
@ddikman
ddikman / routes.dart
Last active Sep 23, 2021
Example of feature flagging
View routes.dart
void registerRoutes() {
// ...
final useNewArticlePage = isDebugMode == true;
if (useNewArticlePage) {
routing.register(Routes.Article, (context, param) => FixedSizeArticlePage());
} else {
routing.register(Routes.Article, (context, param) => ArticlePage());
}
// ....
}
@ddikman
ddikman / input.rb
Created Jul 28, 2021
Example of cucumber step definitions
View input.rb
Then("the first match is {string}") do |title|
expect(find(:css, '#search div h3', :match => :first).text).to eq(title)
end
When("tapping search") do
click_button('btnK')
end
View google-search.feature
Feature: Google Search
Scenario: Searching a term will generate results
Given the user is on google top page
When searching for "greycastle ab software"
Then the first match is "Greycastle - Greycastle"
Scenario: The lucky feature will navigate straight to the first match
Given the user is on google top page
When entering "greycastle ab software"
@ddikman
ddikman / gitlab-ci.yaml
Created Jul 3, 2021
A single step flutter lint, test and coverage pipeline for gitlab
View gitlab-ci.yaml
cache:
paths:
- /flutter/bin/cache/dart-sdk
build:
image: greycastle/jreader:2.3.0
script:
- flutter analyze
- pub global activate junitreport
- export PATH="$PATH":"$HOME/.pub-cache/bin"
@ddikman
ddikman / gitlab-ci.yaml
Created Jul 3, 2021
Flutter three step build and test job
View gitlab-ci.yaml
stages:
- lint
- test
- coverage
default:
image: greycastle/jreader:2.3.0
cache:
paths: