Skip to content

Instantly share code, notes, and snippets.

View Miha-x64's full-sized avatar
🍵
へ‿(◉‿◉)‿ㄏ

Mike Miha-x64

🍵
へ‿(◉‿◉)‿ㄏ
View GitHub Profile
@Miha-x64
Miha-x64 / BoundService.kt
Last active January 5, 2020 14:48
Boilerplate for bound services (may become a part of http://github.com/Miha-x64/Flawless) later
package net.aquadc.flawless.service
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Binder
import android.os.IBinder
/**
@Miha-x64
Miha-x64 / Handlecutor.java
Last active May 22, 2018 15:21
It is an android.os.Handler and java.util.concurrent.Executor at the same time.
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import java.util.concurrent.Executor;
public class Handlecutor extends Handler implements Executor {
public Handlecutor(@NonNull Looper looper) {
@Miha-x64
Miha-x64 / ArrayLists.java
Last active February 1, 2022 12:30
Utility-class for marking several ArrayList elements as removed and removing them all then.
package net.aquadc.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* For lists with O(n) random-deletion time (array-based lists, like {@link ArrayList}),
* it's faster to mark items as removed and them sweep them all together.
package whatever
import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Converter
import retrofit2.Retrofit
@Miha-x64
Miha-x64 / FirstLastItemSpacesDecoration.java
Created July 13, 2017 11:43
RecyclerView decoration which adds indentation in the beginning and in the end of content.
package net.aquadc.commonandroid.lists;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class FirstLastItemSpacesDecoration extends RecyclerView.ItemDecoration {
private final int directSpace;
private final int reverseSpace;
@Miha-x64
Miha-x64 / enums.kt
Last active February 9, 2022 10:00
Enum extensions for Kotlin, superseded by https://github.com/Miha-x64/Kotlin-MPP_Collection_utils
package net.aquadc.common
// Gist: https://gist.github.com/Miha-x64/5f626228b34175f827734596d6701008
import java.util.*
// maps
inline fun <reified K : Enum<K>, V> enumMapOf(): MutableMap<K, V> {
return EnumMap<K, V>(K::class.java)
}
@Miha-x64
Miha-x64 / DynamicActivity.java
Created May 23, 2017 14:58
An activity which copies an APK from assets to private directory, and loads a class and resources from it.
package whatever.dynamicapkloading;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;
package net.aquadc.commonandroid
import android.content.res.Resources
import java.text.SimpleDateFormat
import java.util.*
/**
* Returns text representation of `Date` and time (in millis)
* after which this value should be updated;
* time can be -1, which means that no update will ever be needed
@Miha-x64
Miha-x64 / EnumSetTypeAdapterFactory.kt
Last active February 9, 2022 10:01
TypeAdapter(Factory) for enums with no reflective @SerializedName lookup; TypeAdapterFactory whichs treats Set<E> as EnumSet<E>
package net.aquadc.common
import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import java.lang.reflect.ParameterizedType
import java.util.*
/**
@Miha-x64
Miha-x64 / ImDate.kt
Last active August 30, 2017 17:08
Immutable Date subclass
package net.aquadc.common
import java.util.*
import kotlin.DeprecationLevel.ERROR
import kotlin.UnsupportedOperationException as UOE
/**
* Created by mike on 17.02.17
*/