This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThemeUtils { | |
public static int getResourceIdForAttribute(@AttrRes int attrId, Activity activity) { | |
TypedValue outValue = new TypedValue(); | |
activity.getTheme().resolveAttribute(attrId, outValue, true); | |
return outValue.resourceId; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rx = require('rx') | |
var MAX_RETRIES = 4 | |
Rx.Observable.throw(new Error("always fails")) | |
.retryWhen(function (errors) { | |
return Rx.Observable.zip( | |
Rx.Observable.range(1, MAX_RETRIES), errors, function (i, e) { return i }) | |
.flatMap(function (i) { | |
console.log("delay retry by " + i + " second(s)"); | |
return Rx.Observable.timer(i * 1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getGitCommit() { | |
return 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() | |
} | |
def getGitTag() { | |
def p = Runtime.getRuntime().exec("git describe HEAD --abbrev=0") | |
if (p.waitFor() != 0) { | |
return "none" // no tag | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* If [assumed] is non-null, converts it to a non-null type and executes [block] on the non-null | |
* type as an extension function (like with() in the Standard kotlin library) | |
* | |
* Similar to Swift's "if let = ..." construct. | |
*/ | |
fun <T> if_let(assumed : T?, block : T.() -> Unit) { | |
if (assumed == null) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function kill_one_ps() { | |
ps -A | grep $1 | egrep -m1 -o '^\d+' | xargs kill -9 | |
} | |
function kill_all_ps() { | |
ps -A | grep $1 | egrep -o '^\d+' | xargs kill -9 | |
} | |
# aliases | |
alias kill_adb="kill_all_ps Genymotion ; kill_one_ps 'adb.*server'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Asynchronous equivalent of filterNotNull in Kotlin's stdlin (kotlin.collections) | |
*/ | |
fun <T> Observable<T?>.filterNotNull() : Observable<T> { | |
return this.filter { item -> item != null }.map { it!! } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add this to (e.g.) an EditText via addTextChangedListener() to prevent any user input | |
* that doesn't match its supplied regex. | |
* | |
* Inspired by original Java code here: http://stackoverflow.com/a/11545229/1405990 | |
*/ | |
class RegexMaskTextWatcher(regexForInputToMatch : String) : TextWatcher { | |
private val regex = Pattern.compile(regexForInputToMatch) | |
private var previousText: String = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add this to (e.g.) an EditText via addTextChangedListener() to only allow user input that | |
* is accepted by the supplied predicate. | |
* | |
* e.g. | |
* emailEditText.addTextChangedListener(PredicateTextWatcher({ presenter.isValidEmail(it) }) | |
* | |
* Inspired by original Java code here: http://stackoverflow.com/a/11545229/1405990 | |
*/ | |
class PredicateTextWatcher(val predicate : (String) -> Boolean) : TextWatcher { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# adb must be running in root mode to broadcast intents | |
adb -e root | |
adb -e shell settings put global airplane_mode_on 1 | |
# radios won't actually turn off until this is broadcasted | |
adb -e shell am broadcast -a android.intent.action.AIRPLANE_MODE |
OlderNewer