Skip to content

Instantly share code, notes, and snippets.

View Pooh3Mobi's full-sized avatar

Pooh3Mobi Pooh3Mobi

View GitHub Profile
public class ReflectionUtil {
public static Object getField(Object object, String strName) throws NoSuchFieldException, IllegalAccessException {
if(object == null || object.getClass() == null) return null;
Field field = object.getClass().getField(strName);
return field.get(object);
}
public static Object getDeclaredField(Object obj, String name)
throws SecurityException, NoSuchFieldException,
@Pooh3Mobi
Pooh3Mobi / Kurrying.kt
Last active November 7, 2017 19:19
Currying at Kotlin Sample
fun main(args: Array<String>) {
// x + y
val sum2Ints : (Int, Int) -> Int = { x, y -> x + y }
val curriedSum2Ints = sum2Ints.curried()
val applied1IntSum2Ints = curriedSum2Ints(5)
println(applied1IntSum2Ints(8)) // 13
// x + y + z
val sum3Ints : (Int, Int, Int) -> Int = { x, y, z -> x + y + z }
@Pooh3Mobi
Pooh3Mobi / init.el
Last active November 30, 2017 05:46
emacs setting for clojure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;;
;;;
;;; general
;;;
;;; setup language env
(set-language-environment "UTF-8")
;;; setup your user-emacs-directory
(let* ((user-init-dir (file-name-as-directory (or (getenv "EMACS_USER_DIRECTORY")
@Pooh3Mobi
Pooh3Mobi / rx-with-retrofit-fragment-code-sample.kt
Last active December 23, 2017 10:50
List -> itr -> toList -> subscribe -> recyclerview.adapter = adapter
class TpcsFgmt : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val sLoadingVisible = RxView.visibility(loadingTextView, View.INVISIBLE)
val sRVVisible = RxView.visibility(list, View.INVISIBLE)
val sIsLoading = BehaviorSubject.createDefault(false)
sIsLoading.observeOn(AndroidSchedulers.mainThread()).subscribe { loading ->
sLoadingVisible.accept(loading)
sRVVisible.accept(!loading)
@Pooh3Mobi
Pooh3Mobi / RxErrorHandlingSample.kt
Last active December 23, 2017 11:00
rx-error-handling-sample
package mobi.pooh3.rxmediaviewer
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@Pooh3Mobi
Pooh3Mobi / BollingerBand.py
Last active February 9, 2018 03:32
Signal source for QuantX
def _mavg_signal(data):
....
# bollinger band %B day 20
c = data["close_price_adj"].fillna(method='ffill')
m20 = c.rolling(window=20, center=False).mean()
s20 = c.rolling(window=20, center=False).std()
ub = m20 + s20 * 2
lb = m20 - s20 * 2
pb = (c - lb) / (ub - lb)
....
sealed class Row {
data class Header(
val columns: List<String>
) : Row()
data class Item(
val id: Long,
val name: String,
val price: Long?
) : Row()
// Row.kt
sealed class Row {
data class Header(
val columns: List<String>
) : Row()
data class Item(
val id: Long,
val name: String,
val price: Long?
@Pooh3Mobi
Pooh3Mobi / FRPSeekBarMetronomeFragment.kt
Last active March 18, 2018 02:00
Kotlin-FRP Metronome sample code
import android.media.ToneGenerator
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.jakewharton.rxbinding2.widget.text
import com.jakewharton.rxbinding2.widget.userChanges
import io.reactivex.Observable
@Pooh3Mobi
Pooh3Mobi / DiffProgramming01.kt
Created July 11, 2018 14:59
differential programming at kotlin
interface AFunctionExecutor {
fun execute(tag: String = "None", name: String = "Taro", age: Int=32)
}
class DefaultFunctionExecutor : AFunctionExecutor {
override fun execute(tag: String , name: String, age: Int) = println("[$tag] $name($age)")
}
class SoccerFunctionExecutor : AFunctionExecutor {
override fun execute(tag: String, name: String, age: Int) {