This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 計算結果を束縛 | |
fun judgeBMI(weight: Double, height: Double): String { | |
return when ( | |
val bmi = (height / 100) | |
.let { weight / (it * it) } | |
) { | |
in 0.0..18.5 -> "Low weight $bmi" | |
in 18.5..25.0 -> "Normal (healthy weight)" | |
in 25.0..30.0 -> "Obese Class I" | |
in 30.0..35.0 -> "Obese Class II" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoginFormFragment : Fragment() { | |
companion object { | |
fun newInstance() = LoginFormFragment() | |
} | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A-D blocking thread | |
fun testA() { | |
println(1) | |
Thread.sleep(1000) | |
println(2) | |
Thread.sleep(1000) | |
println(3) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.ViewModel | |
import io.reactivex.Flowable | |
import io.reactivex.processors.BehaviorProcessor | |
import io.reactivex.schedulers.Schedulers | |
// | |
// In/Out/State | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
setSupportActionBar(toolbar) | |
fab.setOnClickListener { view -> | |
main() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.AssertionError | |
data class Point(val x: Float, val y: Float) | |
fun pointAt(x: Float, y: Float) = Point(x, y) | |
data class Line(val p1: Point, val p2: Point) | |
infix fun Point.to(other: Point) = Line(this, other) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mvvmlab | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import androidx.databinding.DataBindingUtil | |
import androidx.databinding.ObservableBoolean | |
import androidx.databinding.ObservableField | |
import androidx.databinding.ObservableInt | |
import androidx.lifecycle.* | |
import com.example.mvvmlab.databinding.ActivityMainBinding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/52441962 | |
fun String.runCommand( | |
workingDir: File = File("."), | |
timeoutAmount: Long = 60, | |
timeoutUnit: TimeUnit = TimeUnit.SECONDS, | |
onErrorReturn: (Throwable) -> String = { "error: ${it.message}" } | |
): String { | |
val result = runCatching { | |
val parts = this.split("\\s".toRegex()) | |
val proc = ProcessBuilder(*parts.toTypedArray()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Clipboard.onChanged(block: (String?) -> Unit) { | |
addFlavorListener { e -> block((e.source as Clipboard).clipboardString) } | |
} | |
var Clipboard.clipboardString: String? | |
set(value) { | |
val ss = StringSelection(value) | |
setContents(ss, ss) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
import androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleObserver | |
import androidx.lifecycle.OnLifecycleEvent | |
object IndentProvider { | |
private var depth = 0 | |
private const val SPACE = " " |