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 / 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;
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 / 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.
@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 / 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 / proguard-rules.pro
Last active March 13, 2023 07:27
Healthy person's ProGuard rules for Android and Kotlin.
# preverify is useful only for J2ME
# R8 doesn't preverify by default
#-dontpreverify
-optimizationpasses 5
# this seems to be enough
# remove indirection
-allowaccessmodification
@Miha-x64
Miha-x64 / SpanningLinearLayoutManager.java
Last active May 24, 2023 16:37 — forked from heinrichreimer/LICENSE
LinearLayoutManager which distributes available space equally between all items. Changed: works also when items are added or removed.
package net.aquadc.recycler;
import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
/**
@Miha-x64
Miha-x64 / unblend.rs
Last active April 18, 2019 08:30
Rust script for extracting a transparent colour from the given pre-blent opaque colours
use std::env;
use std::io;
use std::io::Write;
use std::str::FromStr;
#[macro_use]
extern crate lazy_static;
fn main() {
// Java(?) way
interface Fraction<E extends Exception> {
int numerator() throws E;
int denominator() throws E;
}
class FracStatic implements Fraction<RuntimeException> // don't force catching
class FracSum<E1, E2> implements Fraction<EitherException<E1, E2>> // impossible due to type erasure
// Kotlin, Scala, Rust way

Singleton

  1. Roll-your-own lazy singleton

    public final class Single {
        private static Single INSTANCE;
        private Single() {}