Skip to content

Instantly share code, notes, and snippets.

View talenguyen's full-sized avatar
🎯
Focusing

Nguyen Truong Giang talenguyen

🎯
Focusing
View GitHub Profile
@talenguyen
talenguyen / CleanBuildHistory.groovy
Last active February 13, 2020 04:34
Jenkins cleanup
import com.cloudbees.hudson.plugins.folder.AbstractFolder
import hudson.model.AbstractItem
import groovy.transform.Field
def jobName = "Android-Verify" // jobName can be set to a Job or a Folder. If a folder, it will clean all jobs in that folder
//jobName should be full job name from root if mutliple levels down(for example "Folder1/Folder2/Job")
def resetBuildNumber = false // If this is true, the build number will be set back to 1
@Field def dryRun = false // If this is true, the job will run without deletion.
@Field def cleanedJobsTotal = 0
@Field def keepDays = 0 // Days to keep.
@talenguyen
talenguyen / gradle.md
Created May 2, 2019 10:45
Gradle tasks come to rescue

Gradle tasks:

  • --recompile-scripts: Forces scripts to be recompiled while bypassing caching.
  • --rerun-tasks: Forces Gradle to rerun all tasks and ignore any task optimizations.
@talenguyen
talenguyen / FileUtils.java
Created April 24, 2019 02:57
File utilities that support generate hash, unzip, etc.
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import okio.BufferedSink;
import okio.BufferedSource;
@talenguyen
talenguyen / android_sdk_install.sh
Created April 9, 2019 05:11
shell script to install Android SDK
#!/usr/bin/env bash
set -xeuo pipefail
USER_NAME=$1
SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
ANDROID_HOME="/home/${USER_NAME}/android-sdk"
# Download Android SDK
@talenguyen
talenguyen / AndroidJenkinsDockerfile
Last active November 29, 2019 07:34
Dockerfile to create Jenkins image. This image is includes essential tools that were be used internal in Android Development @tiki #docker, #android, #tiki
FROM jenkins/jenkins:lts
USER root # if we want to install via apt
RUN apt-get update
## Install essential libs
RUN apt-get install -y build-essential dh-autoreconf
## Install Node
@talenguyen
talenguyen / build.gradle
Created March 20, 2019 10:45
Run lint/test on module
// Define custom lint task, say customLintCheck and includes all lint tasks from module
def customLintCheck = tasks.register("customLintCheck") {
group "verification" // Add task to verification group.
description "Run lint check for all"
dependsOn gradle.includedBuild('productdetail').task(':productdetail:lintDebug')
}
// Make customLintCheck run along with :app:lintDebug
subprojects {
@talenguyen
talenguyen / App.kt
Created February 22, 2019 00:20
Declare StrictMode to detect performance issue
class App: Application {
override fun onCreate() {
super.onCreate()
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyDeath()
.penaltyLog()
.build())
@talenguyen
talenguyen / arg.md
Last active November 1, 2019 04:21
Shell tips & tricks

Parse argument from shell command.

  • $1: first argument
  • ${1:-2}: first argument or fallback to 2
@talenguyen
talenguyen / CrashReportingTree.java
Last active January 31, 2019 03:51
CrashReportingTree logging for Timber
/** A tree which logs important information for crash reporting. */
class CrashReportingTree extends Tree {
@Override public boolean isLoggable(int priority, @Nullable String tag) {
return priority >= INFO;
}
@Override protected void log(int priority, String tag, Throwable t, String message) {
if (priority == Log.VERBOSE || priority == Log.DEBUG) {
return;
}
@talenguyen
talenguyen / ktlint.gradle
Created January 20, 2019 23:28
ktlint configuration
// kotlin-gradle-plugin must be applied for configuration below to work
// (see https://kotlinlang.org/docs/reference/using-gradle.html)
repositories {
jcenter()
}
configurations {
ktlint
}