Skip to content

Instantly share code, notes, and snippets.

View harryhan24's full-sized avatar

harry han harryhan24

View GitHub Profile
fun <T> backoff(times: Int = Int.MAX_VALUE, predicate: (Throwable, Int) -> Boolean = { _, _ -> true }): ObservableTransformer<T, T> {
return ObservableTransformer {
it.retryWhen { attempts ->
val counter = AtomicInteger()
attempts.takeWhile { e -> counter.getAndIncrement() < times && predicate(e, counter.get()) }
.flatMap { Observable.timer(counter.get().toLong(), TimeUnit.SECONDS) }
}
}
}
@harryhan24
harryhan24 / UIView+Extensions.swift
Created February 5, 2019 22:25 — forked from orgmir/UIView+Extensions.swift
Extensions for UIView that help out when building layouts manually!
//
// UIView+Extensions.swift
//
// Created by Luis Ramos on 17/5/18.
//
import UIKit
extension UIView {
@harryhan24
harryhan24 / Search my gists.md
Created January 6, 2019 21:00 — forked from santisbon/Search my gists.md
How to search gists

Enter this in the search box along with your search terms:

Get all gists from the user santisbon.
user:santisbon

Find all gists with a .yml extension.
extension:yml

Find all gists with HTML files. language:html

@harryhan24
harryhan24 / RoundedBottomSheetDialogFragment.kt
Created December 25, 2018 08:49 — forked from ArthurNagy/RoundedBottomSheetDialogFragment.kt
Rounded modal bottom sheet as seen in new Google products(Tasks, News, etc.), described in this article: https://medium.com/halcyon-mobile/implementing-googles-refreshed-modal-bottom-sheet-4e76cb5de65b
package com.your.package
import android.app.Dialog
import android.os.Bundle
import com.your.package.R
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
/**
* BottomSheetDialog fragment that uses a custom
@harryhan24
harryhan24 / sequelize-schema-file-generator.js
Created December 21, 2018 07:12 — forked from paulmowat/sequelize-schema-file-generator.js
Sequelize Migration Generator from Models
// ////////////////////////////////
// How to use?
// 1. Make sure you've ran the `sequelize init` before (It should create `config`,`seeders`,`migrations` folders).
// 2. Run it with `node sequelize-schema-file-generator.js`
// 3. Review the generated migrations inside of the `migrations` folder.
// ////////////////////////////////
/* jscs:disable */
/* jshint ignore:start */
var path = require('path')
@harryhan24
harryhan24 / Data.kt
Created October 13, 2018 04:59 — forked from florina-muntenescu/Data.kt
Using RoomDatabase#Callback to pre-populate the database - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 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
private val callback = object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
try {
// First time to database was created, check if user upgraded from a previous
// version of the app that was using ORMLite and migrate data if needed.
val context = TradeMeApp.getContext()
val previousDB = context.applicationContext.getDatabasePath(PREVIOUS_DATABASE_FILE)
if (previousDB.exists()) {
MigrateToRoom(previousDB, context.component.database).execute()
}
@harryhan24
harryhan24 / BindingViewModelAdapter.kt
Created September 28, 2018 23:19 — forked from halcyonmobiledev/BindingViewModelAdapter.kt
Abstract RecyclerView adapter which uses DataBinding & MVVM pattern to bind data to each view item
/*
* Copyright (c) 2017 Halcyon Mobile
* http://www.halcyonmobile.com
* All rights reserved.
*/
import android.databinding.DataBindingUtil
import android.databinding.OnRebindCallback
import android.databinding.ViewDataBinding
import android.support.annotation.CallSuper
import android.support.annotation.LayoutRes
@harryhan24
harryhan24 / LiveDataExtensions.kt
Created September 28, 2018 21:44 — forked from jamiesanson/LiveDataExtensions.kt
LiveData NonNull Observers
/**
* Extends LiveData allowing Kotlin DSL for onChanged callback usage
*/
fun <T> LiveData<T>.observeNonNull(lifecycleOwner: LifecycleOwner, onItem: (T) -> Unit) {
this.observe(lifecycleOwner, object : NonNullObserver<T> {
override fun onChangedNonNull(t: T) {
onItem(t)
}
})
}
class MainViewModel {
val visible = ObservableBoolean(false)
}