Skip to content

Instantly share code, notes, and snippets.

View swissonid's full-sized avatar
💙
Learning new things

Patrice Müller swissonid

💙
Learning new things
View GitHub Profile
@swissonid
swissonid / SDKUtils.kt
Last active June 19, 2019 12:29
Set SDK version of android in a UnitTest. Using some reflection magice
@Test
fun `someTest-which-should-test-diffrent-behavior-on-diffrent-sdk-version`() {
setSDK(Build.VERSION_CODES.N)
//some test
setSDK(Build.VERSION_CODES.M)
// some test again with diffrent SDK verion
}
@swissonid
swissonid / firebase_timestamp_serializer_plugin.dart
Created August 15, 2019 06:38
Plugin for built_value to serialize the timestamp for firebase
import 'package:built_value/serializer.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class FirebaseTimestampSerializerPlugin implements SerializerPlugin {
@override
Object beforeSerialize(Object object, FullType specifiedType) {
if (object is DateTime && specifiedType.root == DateTime)
return object.toUtc(); //Timestamp.fromMicrosecondsSinceEpoch(object);
return object;
}
@swissonid
swissonid / prepare-commit-msg
Last active October 15, 2019 06:47
prepare-commit-msg
#!/bin/bash
# This hook is based on https://medium.com/@nicklee1/prepending-your-git-commit-messages-with-user-story-ids-3bfea00eab5a
## HOW TO INSTALL
# GLOBAL FOR ALL FUTURE PROJECT
# git config --global init.templatedir '~/.git-templates'
# mkdir -p ~/.git-templates/hooks
# touch ~/.git-templates/hooks/prepare-commit-msg
@swissonid
swissonid / ktlint_pre_commit_hook.rb
Created September 27, 2023 12:21
pre-commit Hook which formats your kotlin file with ktling
#!/usr/bin/env ruby
require 'open3'
class KtlintPreCommitHook
def self.run
puts "Running pre commit hook"
check_ktlint_availability
files_needs_formatting = check_changed_files
auto_format_changed_files(files_needs_formatting)
end