Skip to content

Instantly share code, notes, and snippets.

View pavlospt's full-sized avatar
💻
Refactoring something somewhere

Pavlos-Petros Tournaris pavlospt

💻
Refactoring something somewhere
View GitHub Profile
ext.set("alwaysUpdateBuildId", false)
val alwaysUpdateBuildId by extra { false }
(this as ExtensionAware).extra["alwaysUpdateBuildId"] = false
create("baseDebug") {
isDebuggable = true
matchingFallbacks = listOf("debug")
signingConfig = signingConfigs.getByName("debug")
ext.set("alwaysUpdateBuildId", false)
}
create("someStagingEnv") {
initWith(getByName("baseDebug"))
}
@delegate:ColorInt
val someColor: Int by lazy {
ContextCompat.getColor(context, R.color.some_color)
}
suspend fun <Response> Task<Response>.suspended(): Response = suspendCoroutine { continuation ->
addOnSuccessListener { continuation.resume(it) }
addOnFailureListener { continuation.resumeWithException(it) }
}
class TaskObservable<T>(private val task: Task<T>) : ObservableOnSubscribe<T> {
override fun subscribe(emitter: ObservableEmitter<T>) {
task
.addOnSuccessListener { t ->
if (!emitter.isDisposed) {
emitter.onNext(t)
emitter.onComplete()
}
}
@pavlospt
pavlospt / Random.kt
Created October 8, 2018 12:23
apply vs with
val foo = Foo()
.setSomething1(1)
.setSomething2(2)
.apply {
if (aCondition == true) setSomething3(3)
}
.setSomething4(4)
gradle.taskGraph.whenReady { graph ->
// Be careful if you are also using --continue elsewhere.
if (gradle.startParameter.continueOnFailure) {
graph.allTasks.findAll { it.name ==~ /yourTestTask/ }*.ignoreFailures = true
}
}
def postCommitStatus(params = [:]) {
withCredentials([
string([credentialsId: 'your-credentials-id', variable: 'GITHUB_API_TOKEN'])
]) {
def authHeaders = [[name: 'Authorization', value: "token ${GITHUB_API_TOKEN}"]]
def commit = params.commit
def requestBody = params.body
def statusUrl = "https://api.github.com/repos/repo-owner/repo-name/statuses/${commit}"
try {
def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: requestBody, url: statusUrl, customHeaders: authHeaders
@pavlospt
pavlospt / demo.sh
Created January 12, 2018 14:59 — forked from rock3r/README.md
A simple bash script to enable demo mode on a Marshmallow+ device via ADB (based on http://bit.ly/295BHLx)
#!/bin/sh
CMD=$1
if [[ $ADB == "" ]]; then
ADB=adb
fi
if [[ $CMD != "on" && $CMD != "off" ]]; then
echo "Usage: $0 [on|off] [hhmm]" >&2
exit
@pavlospt
pavlospt / MainActivity.java
Created April 20, 2017 19:44
MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(
LithoView
.create(this, ButtonContainer
.create(new ComponentContext(this))