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 / relativeLayout.kt
Last active April 26, 2021 18:46
RelativeLayout for Splitties Views DSL
@file:Suppress("NOTHING_TO_INLINE")
package net.aquadc.commonandroid.views
import android.content.Context
import android.view.View
import android.widget.RelativeLayout
import android.widget.RelativeLayout.TRUE
import androidx.annotation.IdRes
import splitties.views.dsl.core.wrapContent
import kotlin.contracts.ExperimentalContracts
@Miha-x64
Miha-x64 / PicassoTextView.kt
Last active April 26, 2021 18:48
A TextView with Picasso targets for compound drawables
package net.aquadc.commonandroid.views
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.TransitionDrawable
import android.view.View
@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 / FlexibleNumberPicker.java
Last active December 3, 2021 13:45
NumberPicker fork supporting gravity, scale and alpha interpolation, typeface styling, and more.
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Miha-x64
Miha-x64 / Stats.java
Last active February 1, 2022 12:08 — forked from zhong-j-yu/Stats.java
class Stats - used with Stream.collect() to find min and max
package net.aquadc.util;
import java.util.Comparator;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collector;
/**
* Stats of a stream of objects, including {@linkplain #size()}, {@linkplain #min()}, and {@linkplain #max()}.
* <p>This is intended to be used with {@link java.util.stream.Stream#collect}, for example</p>
@Miha-x64
Miha-x64 / CollectionWrap.java
Last active February 1, 2022 12:10
Absolutely normal and safe decorator class which can be easily broken with type-casting
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;
// 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 / 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 net.aquadc.util;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Iterator;
import java.util.function.Consumer;
import java.util.stream.Stream;
public final class Iterators {
private Iterators() {}
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.WorkerThread;
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;