Skip to content

Instantly share code, notes, and snippets.

View Urdzik's full-sized avatar
🏠
Working from home

Viacheslav Urdzik Urdzik

🏠
Working from home
View GitHub Profile
@Urdzik
Urdzik / BetterView.kt
Created April 25, 2021 05:12
Kotlin Delegated (View)
fun TextView.text(): ReadWriteProperty<Any, String> =
object : ReadWriteProperty<Any, String> {
override fun getValue(
thisRef: Any,
property: KProperty<*>
): String = text.toString()
override fun setValue(
thisRef: Any,
property: KProperty<*>, value: String
@Urdzik
Urdzik / BetterSharedPreferences.kt
Created April 25, 2021 04:59
Kotlin Delegated (SharedPreferences)
fun SharedPreferences.string(
defaultValue: String = "",
key: (KProperty<*>) -> String = KProperty<*>::name
): ReadWriteProperty<Any, String> =
object : ReadWriteProperty<Any, String> {
override fun getValue(
thisRef: Any,
property: KProperty<*>
) = getString(key(property), defaultValue)
override fun setValue(
@Urdzik
Urdzik / BetterBundel.kt
Last active November 11, 2022 07:10
Kotlin Delegated(Bundel)
// Universal put function for bundel
fun <T> Bundle.put(key: String, value: T) {
when (value) {
is Boolean -> putBoolean(key, value)
is String -> putString(key, value)
is Int -> putInt(key, value)
is Short -> putShort(key, value)
is Long -> putLong(key, value)
is Byte -> putByte(key, value)
is ByteArray -> putByteArray(key, value)
bool1.withLatestFrom(bool2, BiFunction<Boolean, Boolean, Boolean> { t1, t2 -> t1 && t2 })
.doAfterNext { voidFun() }.onErrorReturnItem(false)
.switchMap { item -> return@switchMap if (item) {
Flowable.create({ sub ->
num.filter { number -> number % 2 == 0 }.take(1)
.subscribeOn(Schedulers.computation())
.map { (1.0 / it).toString() }.subscribe(
{
sub.onNext(it)
}, { error ->
private val ITEM_VIEW_TYPE_HEADER = 0
private val ITEM_VIEW_TYPE_ITEM = 1
class TopRatedMovieAdapter(private val clickListener: MovieListener) :
ListAdapter<DataItem, RecyclerView.ViewHolder>(MovieNightDiffCallback()) {
private val adapterScope = CoroutineScope(Dispatchers.Default)
fun addHeaderAndSubmitList(list: List<SmallMovieList>?) {
val zip = BiFunction<Boolean, Boolean, Boolean> { t1, t2 -> t1 == t2 }
val bool1 =
Flowable.fromArray(true, false, true, false, false)
val bool2 =
Flowable.fromArray(false, true, true, false, true).zipWith(bool1, zip).subscribeOn(
Schedulers.io()).onErrorReturn { t: Throwable ->
eLog(t)
false
}
[
{
"Title": "They Shall Not Grow Old",
"Year": 2018,
"Rated": "R",
"Released": "01 Feb 2019",
"Runtime": "99 min",
"Genre": "Documentary, History, War",
"Director": "Peter Jackson",
"Writer": "Peter Jackson",
public class Square<T extends Number> {
private T value;
public Square(T value) {
this.value = value;
}
public T getValue() {
return value;
public static void main(String[] args) {
HashMap<String, Long> myHashMap = new HashMap<>();
myHashMap.put("terramare", 380432275389L);
myHashMap.put("Mont blanc", 380680558887L);
for(Map.Entry<String, Long> entry: myHashMap.entrySet())
System.out.println(entry.getKey() + " - " + entry.getValue());
}
public class Triangl {
private int one;
private int two;
private int three;
public Triangl(int one, int two, int three) {
this.one = one;
this.two = two;
this.three = three;