Skip to content

Instantly share code, notes, and snippets.

🍵
Writing *QL and SQLite support for Lychee data-binding lib.

Mike Miha-x64

🍵
Writing *QL and SQLite support for Lychee data-binding lib.
Block or report user

Report or block Miha-x64

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Miha-x64
Miha-x64 / CollectionWrap.java
Last active Oct 14, 2019
Absolutely normal and safe decorator class which can be easily broken with type-casting
View CollectionWrap.java
import java.util.Collection;
import java.util.Comparator;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NavigableSet;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
View Java and Kotlin antipattern evolution.md

Singleton

  1. Roll-your-own lazy singleton

    public final class Single {
        private static Single INSTANCE;
        public Single getInstance() {
            return INSTANCE != null
View ErrorHandling.java
// 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
@Miha-x64
Miha-x64 / unblend.rs
Last active Apr 18, 2019
Rust script for extracting a transparent colour from the given pre-blent opaque colours
View unblend.rs
use std::env;
use std::io;
use std::io::Write;
use std::str::FromStr;
#[macro_use]
extern crate lazy_static;
fn main() {
@Miha-x64
Miha-x64 / SpanningLinearLayoutManager.java
Last active Jun 18, 2019 — forked from heinrichreimer/SpanningLinearLayoutManager.java
LinearLayoutManager which distributes available space equally between all items. Changed: works also when items are added or removed.
View SpanningLinearLayoutManager.java
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 / proguard-rules.pro
Last active Apr 11, 2019
Healthy person's ProGuard rules for Android and Kotlin.
View proguard-rules.pro
# shrink libraries (this in enabled by default since v. 4.5)
-dontskipnonpubliclibraryclasses
# preverify is useful only for J2ME
-dontpreverify
-optimizationpasses 5
# this seems to be enough
-overloadaggressively
@Miha-x64
Miha-x64 / BoundService.kt
Last active Dec 5, 2018
Boilerplate for bound services (may become a part of http://github.com/Miha-x64/Flawless) later
View BoundService.kt
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
It is an android.os.Handler and java.util.concurrent.Executor at the same time.
View Handlecutor.java
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 Sep 17, 2019
Utility-class for marking several ArrayList elements as removed and removing them all then.
View ArrayLists.java
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.
View UnwrappingConverterFactory.kt
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
You can’t perform that action at this time.