Skip to content

Instantly share code, notes, and snippets.

View Pooh3Mobi's full-sized avatar

Pooh3Mobi Pooh3Mobi

View GitHub Profile
@Pooh3Mobi
Pooh3Mobi / TheIntersectionOfTwoLines.kt
Last active March 26, 2019 01:05
the intersection of two lines
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)
@Pooh3Mobi
Pooh3Mobi / MainActivity.kt
Last active February 11, 2019 02:43
Kotlin Parallel performance examples.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
main()
}
@Pooh3Mobi
Pooh3Mobi / FRPLoadingViewModel.kt
Last active January 19, 2019 06:58
Learning FRP with Android + Kotlin + ViewModel + DataBing inspired The Elm Architecture
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
//
@Pooh3Mobi
Pooh3Mobi / Sample01.kt
Last active January 17, 2019 15:52
Kotlin Coroutines Sample 01
// A-D blocking thread
fun testA() {
println(1)
Thread.sleep(1000)
println(2)
Thread.sleep(1000)
println(3)
}
@Pooh3Mobi
Pooh3Mobi / LoginForm01.kt
Last active January 14, 2019 12:16
Login form sample with Functional Reactive Programming + DataBinding by Kotlin + Android
class LoginFormFragment : Fragment() {
companion object {
fun newInstance() = LoginFormFragment()
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@Pooh3Mobi
Pooh3Mobi / Binding.kt
Created January 13, 2019 02:31
Kotlin 無理やり束縛例
// 計算結果を束縛
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"
@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
@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 / 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 / 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: