Skip to content

Instantly share code, notes, and snippets.

View warting's full-sized avatar

Stefan Wärting warting

View GitHub Profile
@warting
warting / InvocationInterceptor.kt
Last active January 26, 2024 14:42
InvocationInterceptor
package se.warting.network
import se.warting.logger.Logger
import okhttp3.Interceptor
import okhttp3.Response
import retrofit2.Invocation
/**
* Network interceptor that reports invocations to the error reporter.
*/
@warting
warting / ConditionalHiltApplicationTestRunner.kt
Last active September 5, 2023 06:24
Conditional Hilt application test runner
package se.warting.android
import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.HiltTestApplication
class ConditionalHiltApplicationTestRunner : AndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
@warting
warting / absorb_repo_into_monorepo.sh
Created June 14, 2023 14:21
Script to automate the process of absorbing a standalone Git repository into a monorepo while preserving history, and handling submodules if they exist.
#!/usr/bin/env bash
# This script is used to absorb one git repository into another, making the absorbed
# repository a subdirectory within a monorepo. It allows for easy merging of multiple
# repositories into a monolithic structure (monorepo) while preserving each repository's
# git history. This is useful when you want to consolidate your repositories into a single
# repository for easier management and tracking.
#
# The script works as follows:
# 1. It clones the repositories to be merged into temporary directories.
@warting
warting / build.gradle.kts
Last active May 23, 2023 11:32
Generates a versions.properties files to be used by gradle in android project to set versions on android apps
import java.util.Properties
val versionFile = File("versions.properties")
val versions = Properties().apply {
if (versionFile.exists()) {
FileInputStream(versionFile).use {
load(it)
}
}
@warting
warting / ZoomableImage.kt
Created March 24, 2021 11:25
Jetpack compose zoomable image view example
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.rememberTransformableState
import androidx.compose.foundation.gestures.transformable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@warting
warting / MaterialColors.kt
Created March 11, 2021 09:24
Material design color palette with compose colors written in kotlin
package se.warting.playground.ui.theme
import androidx.compose.ui.graphics.Color
/**
* Material design color palette with compose colors written in kotlin
*
* Taken from https://material.io/design/color/the-color-system.html
*
* These color palettes, originally created by Material Design in 2014, are comprised of colors
@warting
warting / ColorSortActivity
Created February 20, 2015 09:20
How to sort Integer representation of colors in Android as the rainbow
package com.color.activities;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;