Skip to content

Instantly share code, notes, and snippets.

View osipxd's full-sized avatar

Osip Fatkullin osipxd

View GitHub Profile
@osipxd
osipxd / ImmutableList.kt
Last active March 28, 2024 00:19
Transparent wrapper making lists Immutable for compose.
/** Wrapper over the given [list] for Compose to mark this list as [Immutable]. */
@Immutable
@JvmInline
value class ImmutableList<T>(private val list: List<T>) : List<T> by list
/** Returns empty list marked as [Immutable]. */
inline fun <T> immutableListOf(): ImmutableList<T> = ImmutableList(emptyList())
/** Returns a new [Immutable] list of given [elements]. */
@osipxd
osipxd / MakeDebuggableTask.kt
Last active July 4, 2024 18:38
The task to add debuggable=true to obfuscated Android builds
package com.example.build
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
/** Adds `android:debuggable="true"` to the manifest. */
abstract class MakeDebuggableTask : DefaultTask() {
@osipxd
osipxd / 1. Автоматизации и инфраструктура вместо рутины и бойлерплейта.md
Last active October 20, 2023 13:04
Автоматизации и инфраструктура вместо рутины и бойлерплейта

Автоматизации и инфраструктура вместо рутины и бойлерплейта

Материалы к докладу на митап red_mad_robot 15.12.2022

YouTube | Презентация

1. Качество кода

@osipxd
osipxd / DataStoreSerializer.kt
Created November 21, 2022 10:13
DataStore Serializer using kotlinx-serialization
import androidx.datastore.core.DataStore
import androidx.datastore.core.Serializer
import kotlinx.coroutines.flow.first
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import kotlinx.serialization.json.encodeToStream
import java.io.InputStream
import java.io.OutputStream
/**
package io.example
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import okhttp3.Interceptor
import okhttp3.Response
import retrofit2.HttpException
import retrofit2.Invocation
import java.io.IOException
@osipxd
osipxd / 1. sign-app.sh
Last active August 13, 2022 21:23
Script to sign APK and AAB from command line
#!/usr/bin/env bash
#
# Script for APK and AAB signing.
#
# Usage: ./sign-app.sh <format> <path_to_app> <keystore_base64> <properties_base64>
#
# format - should be one of: apk or aab
# path_to_app - path to apk/aab file or '--auto' to automatically detect path
# keystore_base64 - Base64 encoded keystore file
# properties_base64 - Base64 encoded properties file. This file should contain:
@osipxd
osipxd / EpoxyAnchorView.kt
Created February 11, 2022 06:29
Anchor view for DiffUtil.
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.View
import com.airbnb.epoxy.ModelView
/**
* Вьюха-якорь, которая нужна чтобы в зафиксировать положение скролла в `RecyclerView`.
*
@osipxd
osipxd / mac-wattage.sh
Last active February 7, 2024 19:01
Print current Mac wattage (with accuracy up to minute)
#!/usr/bin/env bash
set -euo pipefail
function extract_float_field() {
field=$1
ioreg -rw0 -c AppleSmartBattery |
grep BatteryData |
sed -E "s/.*\"$field\"=([0-9]+).*/\1/" |
xargs -I % lldb --batch --source-quietly --one-line "print/f %" | # Convert IEEE-754 float
@osipxd
osipxd / DataStoreNullableSerializer.kt
Last active November 21, 2022 10:17
Base Serializer class to store nullable values in DataStore
import androidx.datastore.core.DataStore
import androidx.datastore.core.Serializer
import java.io.InputStream
import java.io.OutputStream
abstract class NullableSerializer<T : Any> : Serializer<T?> {
override val defaultValue: T? = null
final override suspend fun readFrom(input: InputStream): T? {
@osipxd
osipxd / change-phone-number.md
Last active January 24, 2024 04:08
Редактирование номера телефона SIM-карты на Android

Что нужно?

  • Root
  • ADB (или любое приложение Terminal на телефоне)

Шаги

Подключение

Подключитесь к телефону через ADB и в открывшейся консоли переключитесь в режим Super User: