Skip to content

Instantly share code, notes, and snippets.

View apaatsio's full-sized avatar

Antti Ahti apaatsio

View GitHub Profile
@apaatsio
apaatsio / pre-commit.sh
Created May 6, 2022 11:06
git pre-commit hook for go projects
#!/bin/sh
echo "ℹ️ Running pre-commit hook"
# go to git root
pushd `git rev-parse --show-toplevel` > /dev/null
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".go$")
if [[ "$STAGED_FILES" = "" ]]; then
@apaatsio
apaatsio / git-setup.sh
Created March 3, 2022 11:08
Useful defaults for global git config
#!/bin/sh
# git config --global user.name "Firstname Lastname"
# git config --global user.email "firstname.lastname@example.com"
git config --global user.useconfigonly true
git config --global pull.ff only
git config --global push.default simple
git config --global rerere.enabled true
git config --global rerere.autoupdate true
git config --global diff.algorithm histogram
git config --global merge.conflictstyle zdiff3
@apaatsio
apaatsio / gnzh-antti.zsh-theme
Created February 11, 2022 23:19
Custom oh-my-zsh theme based on gnzh
setopt prompt_subst
() {
local PR_USER PR_USER_OP PR_PROMPT PR_HOST
# Check the UID
if [[ $UID -ne 0 ]]; then # normal user
PR_USER='%F{green}%n%f'
PR_USER_OP='%F{green}%#%f'
@apaatsio
apaatsio / main.dart
Last active May 18, 2019 11:02
Flutter: Simple counter using ChangeNotifierProvider
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class Counter extends ChangeNotifier {
Counter(int initialValue) : _value = initialValue;
int _value;
set value(int newValue) {
_value = newValue;
notifyListeners();
@apaatsio
apaatsio / build_mode.dart
Created March 19, 2019 12:14
Helper utility to detect build mode (debug, profile, and release) in a Flutter app.
abstract class BuildMode {
static final BuildModeType buildMode = () {
if (const bool.fromEnvironment('dart.vm.product')) {
return BuildModeType.release;
}
var result = BuildModeType.profile;
assert(() {
result = BuildModeType.debug;
return true;
}());
@apaatsio
apaatsio / debug-crashlytics.sh
Created March 16, 2019 19:54
How to debug Crashlytics on Flutter
#!/bin/sh
adb shell setprop log.tag.Fabric DEBUG
adb shell setprop log.tag.CrashlyticsCore DEBUG
adb logcat -s flutter Fabric CrashlyticsCore FirebaseApp libcrashlytics FlutterCrashlytics
@apaatsio
apaatsio / change_commit_date.sh
Created March 4, 2019 09:36
Change any git commit date
# STEP 1
# To change non-root commit
git rebase -i f154548^
# Alternatively, to change the root commit
git rebase -i --root
# STEP 2
# edit the commit you want to change by changing the line
pick f154548 This is a commit message
@apaatsio
apaatsio / size.sh
Last active February 23, 2019 09:12
Project size evaluator for Flutter Create contest 2019. More info: https://flutter.io/create
#!/bin/sh
# Project size evaluator for Flutter Create contest 2019.
# More info: https://flutter.io/create
MAX_SIZE=5120
SIZE=`find . -name "*.dart" | xargs cat | wc -c`
if [ $SIZE -gt $MAX_SIZE ];
[✓] Flutter (Channel master, v0.10.2-pre.25, on Linux, locale en_US.UTF-8)
• Flutter version 0.10.2-pre.25 at /home/antti/tools/flutter
• Framework revision 0edbe726a1 (3 hours ago), 2018-10-22 10:29:00 -0700
• Engine revision 58cdd53f90
• Dart version 2.1.0-dev.7.1.flutter-b99bcfd309
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at /home/antti/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
@apaatsio
apaatsio / coverage.dart
Last active May 23, 2022 13:26
Calculate total test coverage from lcov.info file generated by `flutter test --coverage`
// NOTE: The preferred way is to install lcov and use command `lcov --summary path/to/lcov.info`
// Use this script only if you can't install lcov on your platform.
// Usage: dart coverage.dart path/to/lcov.info
import 'dart:io';
void main(List<String> args) async {
final lcovFile = args[0];
final lines = await File(lcovFile).readAsLines();