Skip to content

Instantly share code, notes, and snippets.

View Pooh3Mobi's full-sized avatar

Pooh3Mobi Pooh3Mobi

View GitHub Profile
@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) {
@Pooh3Mobi
Pooh3Mobi / BinHeapTree.kt
Last active July 19, 2018 15:29
The Fun of Programming with Kotlin
package mobi.pooh3.thefun.fp.bitree
import kotlin.test.assertFalse
import kotlin.test.assertTrue
/*
The Fun of Programming 1-1 [IFPH Section 6.3]
Q, 6つのjoinのうち2つは、そのどちらか一方だけを使うと、すべての木が線形になってしまう。どの二つか?
A, 1 & 5
package input.your.pkg
import android.graphics.Bitmap
import android.view.View
import com.google.firebase.ml.vision.FirebaseVision
import com.google.firebase.ml.vision.common.FirebaseVisionImage
import kotlinx.android.synthetic.main.activity_main.*
public fun MainActivity.detectTextOnCloud(bitmap: Bitmap) {
@Pooh3Mobi
Pooh3Mobi / RepeatableProcess.kt
Last active October 9, 2019 15:32
失敗したらMAXまでリトライし、成功したら次の処理を行うKotlinコード、失敗の情報は保持する
package com.example.forloop
sealed class Result<T, E> {
data class Success<T, E>(val t: T) : Result<T, E>()
data class Failure<T, E>(val e: E) : Result<T, E>()
}
sealed class MultiResult<T, E> {
data class Success<T, E>(val t: T, val ers: List<E>?) : MultiResult<T, E>()
data class Failures<T, E>(val msg: String, val ers: List<E>) : MultiResult<T, E>()
@Pooh3Mobi
Pooh3Mobi / Chapter3_5.kt
Last active September 5, 2018 15:25
Study of Kotlin Domain Modeling : Functional And Reactive Domain Modeling - ADT and Smart Constructor -
@file:Suppress("DataClassPrivateConstructor")
// ADT and Smart Constructor
package com.example.algebra
import java.math.BigDecimal
import java.util.*
// domain modeling part
package com.example
import org.apache.commons.math3.stat.inference.ChiSquareTest
import java.util.Random
/**
* カイ二乗検定のデモ
* https://github.com/komiya-atsushi/dbflute-fes-2014-demo/blob/master/src/main/java/biz/k11i/demo/stat/ChiSquareTestDemo.java
* Kotlin ver
*/
@Pooh3Mobi
Pooh3Mobi / Calc.kt
Last active September 26, 2018 03:40
スタックをつかって電卓風な計算ができるようにしてみた(これ以上の修正は非公開)
package com.example.calc
/*
Copyright 2018 Pooh3Mobi@GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@Pooh3Mobi
Pooh3Mobi / AbstractClassPolymorphismDemo.java
Last active September 28, 2018 08:00
Polymorphism Demo
package com.example.oop;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
// abstract class を継承するやり方のデモコード
public class Demo {
// このコードはデモ用のコードです。書き方についてはチーム単位や会社単位でコーディング規約があると思いますので、
// 製品コードに書くときはそちらを優先してください。
void demo() {
@Pooh3Mobi
Pooh3Mobi / item.xml
Created October 2, 2018 14:14
item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
xmlns:android="http://schemas.android.com/apk/res/android"
@Pooh3Mobi
Pooh3Mobi / MainActivityFragment.kt
Created December 9, 2018 12:09
DataBinding like accessing Model Fields in Layout.
class MainActivityFragment : androidx.fragment.app.Fragment() {
val viewModel = MainViewModel()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = FragmentMainBinding.inflate(inflater)
binding.setLifecycleOwner(this)
binding.vm = viewModel