Skip to content

Instantly share code, notes, and snippets.

@laithnurie
laithnurie / MockServerRule.kt
Last active February 11, 2025 08:49
MockServerRule Test using Ktor
class MockServerRule(
private val appStartUpOverrideMockRequests: List<MockRequest> = emptyList<MockRequest>()
) : TestRule {
private var overrideRequests = mutableMapOf<String, MockRequest>()
override fun apply(
base: Statement,
description: Description
): Statement {
@laithnurie
laithnurie / gradle
Last active October 20, 2023 09:23
One Jacoco task for one single report for multiple gradle sub modules
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.8"
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
group "Reporting"
description "Generate Jacoco coverage reports."
@laithnurie
laithnurie / jacoco.gradle
Created November 5, 2022 12:53
Jacoco Mini
apply plugin: 'jacoco'
task jacocoUnitTestReport(type: JacocoReport, dependsOn: ['testAppDebugUnitTest']) {
reports {
xml.enabled true
html.enabled true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
@laithnurie
laithnurie / LocalServer.kt
Last active January 29, 2025 08:41
Local ktor server
io-ktor = "2.3.11"
io-ktor-ktor-client-android = { module = "io.ktor:ktor-client-android", version.ref = "io-ktor" }
io-ktor-ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "io-ktor" }
io-ktor-ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "io-ktor" }
io-ktor-ktor-server-core = { module = "io.ktor:ktor-server-core", version.ref = "io-ktor" }
object LocalServer {
private var server: CIOApplicationEngine? = null
@laithnurie
laithnurie / library-proguard.pro
Created September 19, 2022 15:27
library proguard
#
# This ProGuard configuration file illustrates how to process a program
# library, such that it remains usable as a library.
# Usage:
# java -jar proguard.jar @library.pro
#
# Specify the input jars, output jars, and library jars.
# In this case, the input jar is the program library that we want to process.
apply plugin: 'maven-publish'
// SDK version is passed in as a parameter when you run the script assemble_and_deploy_lib.sh or you can uncomment the below and use the version from gradle.properties
// version SDK_ARTIFACT_VERSION // version picked up from gradle.properties
String sdkVersion = System.getenv('SDK_VERSION') != null ? System.getenv('SDK_VERSION') : SDK_ARTIFACT_VERSION
publishing {
publications {
sdk(MavenPublication) {
@laithnurie
laithnurie / dependency-upgrade
Created September 16, 2022 15:59
Version catalog android
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+$/
return !stableKeyword && !(version ==~ regex)
}
dependencyUpdates {
resolutionStrategy {
componentSelection {
all {
@laithnurie
laithnurie / detekt.gradle
Created August 18, 2022 15:07
Detekt gradle methods
tasks.register('detektFix', io.gitlab.arturbosch.detekt.Detekt) {
description = "Runs over whole code base without the starting overhead for each module."
autoCorrect = true
parallel = true
setSource(files(projectDir))
include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
exclude("**/test/**/*.kt")
#!/bin/sh
filesToFormat="$(
git --no-pager diff --cached --diff-filter=d --name-only
)"
echo '[git hook] executing gradle detekt and lint before push'
SHOULD_RESET=0
if [[ -n $(git status -s) ]]; then
@laithnurie
laithnurie / detekt.yml
Created August 17, 2022 14:02
Detekt rules
build:
maxIssues: 0
excludeCorrectable: false
weights:
# complexity: 2
# LongParameterList: 1
# style: 1
# comments: 1
config: