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 / 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
@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 / 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 / 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 / commit-msg
Last active August 13, 2021 11:22
Git-hook to add task prefix based on the branch name (feature | hotfix |bugfix)/MIT-1234-
#!/usr/bin/env ruby
#
# Git commit-msg hook. If your branch name is in the form "ABCDE-1234567-postfix", or
# "ABCDE-1234567_postfix", it automatically adds the prefix "ABCDE-1234567 |" to commit
# messages.
#
# Example
# =======
#
# git checkout -b ABCDE-1234567-some-cool-feature
#!/usr/bin/env ruby
#
# Git commit-msg hook. If your branch name is in the form "ABCDE-1234567-postfix", or
# "ABCDE-1234567_postfix", it automatically adds the prefix "ABCDE-1234567 |" to commit
# messages.
#
# Example
# =======
#
# git checkout -b ABCDE-1234567-some-cool-feature
@swissonid
swissonid / i18n.dart
Last active December 5, 2017 08:00
Flutter App
import 'package:bill_scanner/generated/i18n.dart';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
@swissonid
swissonid / WebViewCookieJar.java
Last active November 15, 2017 10:19
Sync Webview Cookie store with OkHttpClient
import android.support.annotation.NonNull;
import android.webkit.CookieManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import okhttp3.Cookie;
import okhttp3.CookieJar;
@swissonid
swissonid / IgnoreSSL.java
Created October 19, 2017 08:21
OkHttp accept all SSL Cetfication
class IgnoreSSL {
static X509TrustManager doNotValidateTrustManager() {
// Create a trust manager that does not validate certificate chains
return new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
@swissonid
swissonid / fileProvider.txt
Created December 12, 2016 08:21
Handle "file://" schema
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Context appContext = mWeakActivity.get().getApplicationContext();
return FileProvider.
getUriForFile(appContext, appContext.getPackageName() + ".provider", file);
}else {
return Uri.fromFile(file);
}
--------------------------------
Add to manifest