Skip to content

Instantly share code, notes, and snippets.

View tiwiz's full-sized avatar

Roberto Orgiu tiwiz

View GitHub Profile
@tiwiz
tiwiz / ESBScraperKtx.kt
Created October 24, 2020 08:45
Scraper for data about lights on Empire State Building
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
private const val ROOT = "https://www.esbnyc.com/"
data class DayLight(
val image: String,
val color: String,
val reason: String,
val date: String

Keybase proof

I hereby claim:

  • I am tiwiz on github.
  • I am tiwiz (https://keybase.io/tiwiz) on keybase.
  • I have a public key whose fingerprint is 10E2 5AD7 29C7 103C E51E 35F2 507C AD03 F738 0B72

To claim this, I am signing this object:

import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.OnLifecycleEvent
import com.nytimes.android.logger.Logger
class LifecycleLogger private constructor(private val className: String,
private val lifecycle: Lifecycle,
private val tag: String) : LifecycleObserver {
class DimOnScrollObserver : OnScrollChangeObserver() {
private lateinit var target: AppCompatActivity
fun attachTo(v: ScrollableViewCompat) {
v.addOnScrollChangeListener(this)
target = v.getAttachedActivity()
}
fun attachTo(v: RecyclerView, host: AppCompatActivity) {
open class ObservableWebView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr), ScrollableViewCompat {
private lateinit var listener : OnScrollChangeObserver
override fun addOnScrollChangeListener(l: OnScrollChangeObserver) {
listener = l
interface ScrollableViewCompat {
fun addOnScrollChangeListener(l: OnScrollChangeObserver)
fun getAttachedActivity() : AppCompatActivity
}
abstract class OnScrollChangeObserver : RecyclerView.OnScrollListener() {
abstract fun onScrollChange(v: View,
scrollX: Int,
scrollY: Int,
oldScrollX: Int,
oldScrollY: Int)
}
@Test
fun coroutine_test() {
val actualWeather = runBlocking {
  getDataAsync().await() 
  }
  …
}
async(start = CoroutineStart.LAZY) {…}
fun View.onClickAsync(action: suspend () -> Deferred<OurType>) {
setOnClickListener {
  launch(UI) {
  val response = action().await()
  bindUiTo(response)
  }
  }
}