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 / Navigator
Created May 30, 2015 19:20
A simple Navigator Class that helps to avoid mistakes by handling with the FragmentManager
public class Navigator{
private final FragmentManager mFragmentManager;
public Navigator(final FragmentManager fragmentManager){
mFragmentManager = fragmentManager;
}
public Fragment getActiveFragment() {
if (mFragmentManager.getBackStackEntryCount() == 0) {
return null;
@swissonid
swissonid / designer.html
Last active August 29, 2015 14:22
designer
<link rel="import" href="../topeka-elements/category-icons.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../paper-tabs/paper-tab.html">
<link rel="import" href="../core-pages/core-pages.html">
<polymer-element name="my-element">
<template>
<style>
@swissonid
swissonid / addContact.sh
Last active June 6, 2016 19:49
Adds 10 Contact to your device
#!/bin/sh
contactstore=./contactstore
temp=~/.tempcontacts
cat ${contactstore}/*vcf > $temp
adb shell pm clear com.android.contacts
adb shell pm clear com.android.providers.contacts
adb push $temp /sdcard/contacts-import.vcf
adb shell am start -t "text/vcard" -d "file:///sdcard/contacts-import.vcf" -a android.intent.action.VIEW com.android.contacts
@swissonid
swissonid / BaseActivity.java
Created September 7, 2016 10:40
LayoutAnnotation
public abstract class BaseActivity extends AppCompatActivity {
@LayoutRes int getLayout() {
int layoutResId =-1;
Class screenType = getClass();
Layout layout = (Layout) screenType.getAnnotation(Layout.class);
if (layout == null) {
throw new IllegalArgumentException(
String.format("@%s annotation not found on class %s", Layout.class.getSimpleName(),
screenType.getName()));
}
@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
@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 / 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 / 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(
#!/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 / 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