Skip to content

Instantly share code, notes, and snippets.

💻
Refactoring something somewhere

Pavlos-Petros Tournaris pavlospt

💻
Refactoring something somewhere
Block or report user

Report or block pavlospt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pavlospt
pavlospt / build.gradle.kts
Created Jul 20, 2019
Root build.gradle.kts
View build.gradle.kts
subprojects {
// Accessing the `PluginContainer` in order to use `whenPluginAdded` function
project.plugins.configure(project = project)
}
// Extension function on `PluginContainer`
fun PluginContainer.configure(project: Project) {
whenPluginAdded {
when (this) {
is AppPlugin -> {
@pavlospt
pavlospt / build.gradle.kts
Created Jul 20, 2019
New module build.gradle.kts
View build.gradle.kts
val compile_sdk_version: Int by rootProject
val min_sdk_version: Int by rootProject
val target_sdk_version: Int by rootProject
android {
compileSdkVersion(compile_sdk_version)
defaultConfig {
minSdkVersion(min_sdk_version)
targetSdkVersion(target_sdk_version)
}
View build.gradle.kts
ext.set("alwaysUpdateBuildId", false)
val alwaysUpdateBuildId by extra { false }
(this as ExtensionAware).extra["alwaysUpdateBuildId"] = false
View build.gradle.kts
create("baseDebug") {
isDebuggable = true
matchingFallbacks = listOf("debug")
signingConfig = signingConfigs.getByName("debug")
ext.set("alwaysUpdateBuildId", false)
}
create("someStagingEnv") {
initWith(getByName("baseDebug"))
}
View ByLazyDelegate.kt
@delegate:ColorInt
val someColor: Int by lazy {
ContextCompat.getColor(context, R.color.some_color)
}
View SuspendedTask.kt
suspend fun <Response> Task<Response>.suspended(): Response = suspendCoroutine { continuation ->
addOnSuccessListener { continuation.resume(it) }
addOnFailureListener { continuation.resumeWithException(it) }
}
View TaskObservable.kt
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()
}
}
View Random.kt
val foo = Foo()
.setSomething1(1)
.setSomething2(2)
.apply {
if (aCondition == true) setSomething3(3)
}
.setSomething4(4)
View root_build.gradle
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
}
}
View PostCommitStatus.groovy
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
You can’t perform that action at this time.