Skip to content

Instantly share code, notes, and snippets.

View runo280's full-sized avatar
🤨

runo280 runo280

🤨
View GitHub Profile
@mirmilad
mirmilad / CoroutinePageKeyedDataSource.kt
Last active June 26, 2020 02:46
Android Paging Library with Kotlin Coroutines
import androidx.paging.PageKeyedDataSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
abstract class CoroutinePageKeyedDataSource<K, V>(private val coroutineContext: CoroutineContext) :
PageKeyedDataSource<K, V>() {
private val job = Job()
@beigirad
beigirad / SampleValidator.kt
Created October 29, 2019 17:58
validation method
class SampleValidator(
val balance: Long?,
val amount: Long?,
val acceptedTerms: Boolean?
) : Validator<SampleValidator> {
override fun validate(): Validation<SampleValidator> {
return when {
balance ?: 0 <= 0 -> Validation.Invalid("بالانس شما کافی نیست")
amount ?: 0 <= 0 -> Validation.Invalid("مبلغ وارد شده صحیح نیست")
amount ?: 0 > balance ?: 0 -> Validation.Invalid("مبلغ وارد شده بیشتر از بالانس شماست")
@rezaiyan
rezaiyan / BObserver.java
Last active October 14, 2019 16:28
Binding Observer with LiveData
public class BObserver<T> extends DisposableObserver<T> {
private StateLiveData<T> liveData;
public BObserver(StateLiveData<T> liveData) {
this.liveData = liveData;
}
@Override
@nekofar
nekofar / dangerous.go
Created September 26, 2019 09:35
Create a Twitter list of following who suspected to be dangerous (AKA Naamn).
package main
import (
"log"
"regexp"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
@sockeqwe
sockeqwe / AdapterDelegateDslExample.kt
Created July 22, 2019 08:19
AdapterDelegates Kotlin DSL
/**
* Let's say we want to display a list of Animals in a RecyclerView.
* The list can contain items of type Dog, Cat and Snake.
*/
// AdapterDelegate for Dog.
fun dogAdapterDelegate(picasso : Picasso) = adapterDelegate<Dog, Animal>(R.layout.item_dog){ // Generics Types means this AdapterDelegate is used if item is instanceof Dog (whole list is List<Anmial>)
// this block is run once in onCreateViewHolder. Think of it as an intializer for a ViewHolder.
val name = findViewById(R.id.name)
val image = findViewById(R.id.image)
#!/bin/bash
#hi
echo [UBUNTU PASSWORD] | sudo -S ls
INPUT_NUMBER=$1
SERVER_URL=""
case $INPUT_NUMBER in
1) SERVER_URL="us2.cisadd3.com:800" ;;
2) SERVER_URL="de.cisadd3.com:800" ;;
3) SERVER_URL="uk.cisadd2.com" ;;
4) SERVER_URL="nl.cisadd2.com" ;;
@RBusarow
RBusarow / TestCoroutineExtension.kt
Last active November 20, 2023 19:03
A JUnit 4 Rule and JUnit 5 Extension for utilizing TestCoroutineDispatcher and TestCoroutineScope from kotlinx.coroutines-test
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext
@dmytrodanylyk
dmytrodanylyk / description.md
Last active June 20, 2022 15:00
Where this dependency comes from?

Did you ever have android build failed​ issue because of dependency resolution?

… or you were curious where all these old rxjava dependencies come from?

You can pretty easy track the module causing issues via following gradle command.

gradlew :root-module:dependencyInsight \
--configuration debugRuntimeClasspath \ // or debugCompileClasspath
--dependency io.reactivex:rxjava:1.1.0 &gt; dependencies.txt // saves result to 'dependencies.txt' file
@alexjlockwood
alexjlockwood / CircleSquareView.kt
Created April 8, 2019 05:59
Inspired by @beesandbombs (twitter.com/beesandbombs)
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
@alexjlockwood
alexjlockwood / animated_cat.xml
Last active September 12, 2023 12:55
Android implementation of an animated cat loading spinner. Inspired by https://twitter.com/marcedwards/status/1109431862030524418
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<group