Skip to content

Instantly share code, notes, and snippets.

View tranngoclam's full-sized avatar
🇻🇳
Vietnam

Lam Tran tranngoclam

🇻🇳
Vietnam
View GitHub Profile
@mohamedebrahim96
mohamedebrahim96 / activity_main2.xml
Last active December 12, 2018 23:10
The function of the button at the center is to call an activity and the TabLayout will be place at the bottom of the screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vacuum.app.cinema.MainActivity">
<!--SOME CODE FOR MY AppBarLayout-->
<!--SOME CODE FOR MY ToolBar-->
@saschpe
saschpe / Enum.kt
Last active May 24, 2022 21:50
Kotlin enum class extension for Android (SharedPreference, Parcelable, Bundle, Intent)
import android.content.SharedPreferences
import android.os.Bundle
import android.os.Parcel
inline fun <reified T : Enum<T>> Bundle.getEnum(key: String, default: T) =
getInt(key).let { if (it >= 0) enumValues<T>()[it] else default }
fun <T : Enum<T>> Bundle.putEnum(key: String, value: T?) =
putInt(key, value?.ordinal ?: -1)
@striboldt
striboldt / build.grade (project instance)
Created November 29, 2017 08:32
Gradle Invalid publication sample
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
@drAlberT
drAlberT / update-docker-compose.sh
Last active September 25, 2020 15:15
Bash script to update docker-compose to the latest release
#!/bin/bash
#
# Updates docker-compose to the latest release
#
# Author: Emiliano Gabrielli <[email protected]>
DESTINATION_FILE="${DESTINATION_FILE:-$(command -v docker-compose)}"
set -e -o pipefail
@bobvawter
bobvawter / ReadWriteMutex.kt
Created August 30, 2017 16:19
A very basic Kotlin-Coroutines ReadWriteMutex example
/**
* Copyright 2017 ModelBox Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vestrel00
vestrel00 / Dagger2SimpleExample.java
Last active October 7, 2021 19:59
A: Dagger.android 2.11 simple example with support for Singleton, PerActivity, PerFragment, and PerChildFragment scopes
// This is a super simplified example of how to use the new dagger.android framework
// introduced in Dagger 2.10. For a more complete, in-depth guide to dagger.android
// read https://proandroiddev.com/how-to-android-dagger-2-10-2-11-butterknife-mvp-part-1-eb0f6b970fd
// For a complete codebase using dagger.android 2.11-2.17, butterknife 8.7-8.8, and MVP,
// see https://github.com/vestrel00/android-dagger-butterknife-mvp
// This example works with Dagger 2.11-2.17. Starting with Dagger 2.11,
// @ContributesAndroidInjector was introduced removing the need to define @Subcomponent classes.
@yitz-grocerkey
yitz-grocerkey / ErrorInterceptor.kt
Created June 13, 2017 19:32
Retrofit RxJava global error handling in Kotlin
// for any errors that should be handled before being handed off to RxJava.
// In other words global error logic.
// An example might be 401 when not logging in
import okhttp3.Interceptor
import okhttp3.Response
class ErrorInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain?): Response {
@adroitandroid
adroitandroid / BaseBottomNavActivity.java
Created January 17, 2017 19:21
Custom bottom navigation bar
abstract class BaseBottomNavActivity extends BaseActivity { // you can directly extend AppCompatActivity
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initOnCreate(savedInstanceState);
getBottomNavigationBar().setOnTabSelectionListener(
new CustomBottomNavigationBar.OnTabSelectionListener() {
@Override
@roylee0704
roylee0704 / dockergrep.sh
Created December 9, 2016 08:24
how to grep docker log
docker logs nginx 2>&1 | grep "127."
# ref: http://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container
@aballano
aballano / RxSnackbarTest.java
Last active February 17, 2017 13:28
Create an observable which emits the action clicked events from a Snackbar.
@RunWith(AndroidJUnit4.class)
public final class RxSnackbarTest {
@Rule public final ActivityTestRule<RxSnackbarTestActivity> activityRule =
new ActivityTestRule<>(RxSnackbarTestActivity.class);
private Snackbar view;
@Before public void setUp() {
RxSnackbarTestActivity activity = activityRule.getActivity();
view = activity.snackbar;