Skip to content

Instantly share code, notes, and snippets.

View christianb's full-sized avatar

Christian Bunk christianb

View GitHub Profile
@christianb
christianb / branches_by_date.sh
Last active October 23, 2017 15:59
Shows list of branches and their age.
#!/bin/bash
#
# Shows all remote branches and their age.
#
# Passing -n <name_of_commiter> shows only the branches last touched by that person.
# Passing -b <branch> shows only branches of that type (release, feature, experimental, etc)
# Passing -t <time> (day, week, month, year)
#
# Arguments can be combined.
@christianb
christianb / chkBranch.sh
Created November 1, 2017 10:21
Easy checkout of branch using grep
# !/bin/sh
# Easy checkout of branch using grep.
#
# example: chkBranch 1789
# or: chkBranch ZAC-4
git pull
count=`git branch | grep -c $1`
@christianb
christianb / android-commands.sh
Last active May 9, 2019 12:36
Usefull Android commands
# shows the apk's certificate
keytool -list -printcert -jarfile <apk>
# shows the keystore details
keytool -list -v -keystore release.jks
@christianb
christianb / python-commands.py
Created May 9, 2019 12:36
Usefull python commands
# call system commands from python
import subprocess
s = "some test"
subprocess.call(["shutdown", "-s", "-t", "10", "-c", s])
@christianb
christianb / LayoutInflater.kt
Last active June 1, 2019 16:33
LayoutInflater, Things to know about attachToRoot
// Something you don't know about Android's LayoutInflater
// by Abhishek Jangra
// https://medium.com/@iabhishek1041/something-you-dont-know-about-android-layoutinflater-6de7709289ac
val inflater: LayoutInflater = LayoutInflater.from(this)
// When attachToRoot is true, the generated view from the a_view XML will automatically attached to the rootView,
// but it will not return the inflated view but the rootView itself.
val rootViewReference = inflater.inflate(R.layout.a_view, rootView, attachToRoot = true)
@christianb
christianb / BaseRecyclerViewHolder.kt
Last active June 2, 2019 11:44
ViewHolder easy view inflation
open class BaseRecyclerViewHolder(@LayoutRes layoutRes: Int, viewGroup: ViewGroup) : RecyclerView.ViewHolder(inflate(layoutRes, viewGroup)) { // Use the private companion function inflate() for getting a view instance.
companion object {
fun inflate(@LayoutRes layoutRes: Int, viewGroup: ViewGroup): View {
return LayoutInflater.from(viewGroup.context).inflate(layoutRes, viewGroup, false)
}
}
}
@christianb
christianb / destructuring.kt
Last active June 1, 2019 16:31
Carfefull with destructuring declaration
// A problem like destructuring declarations
// by Maria Neumayer
// https://medium.com/a-problem-like-maria/a-problem-like-destructuring-declarations-95f10375ea8a
data class Song(
val artist: String,
// val album: String, // once this line gets uncommented
val name: String
)
@christianb
christianb / thread-looper-handler.kt
Last active June 1, 2019 20:16
How to create a Thread with an Looper, called by a Handler
// Understanding Handler and Looper in Android
// by Rahul Rastogi
// https://medium.com/@rastogi.tech/understanding-handler-and-looper-in-android-c6fa673c6822
var handler: Handler? = null
Thread {
Looper.prepare() // Creating a Looper for this thread.
// Creating a Handler for given Looper object.
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
defaultConfig {
applicationId "samples.linhtruong.com.ui_reactive_rxjava_realm"
minSdkVersion versions.minSdk
val matrix = Matrix()
val srcIndex = 0
val dstIndex = 0
val pointCount = 4 // or any other number of points you wanna transform
/**
* Set the matrix such that the specified src points would map to the specified dst points. The
* "points" are represented as an array of floats, order [x0, y0, x1, y1, ...], where each
* "point" is 2 float values.
*/