Skip to content

Instantly share code, notes, and snippets.

View yaraki's full-sized avatar
🏠
Working from home

Yuichi Araki yaraki

🏠
Working from home
  • Google, Inc.
  • Tokyo
View GitHub Profile
@yaraki
yaraki / FlowTest.kt
Created August 8, 2019 07:07
Sleep sort
package com.example.android.flow
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
@yaraki
yaraki / CoroutineTest.kt
Created August 14, 2019 12:50
Channel vs. Flow
package com.example.playground
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.channels.toList
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
@yaraki
yaraki / ClockLiveData.kt
Last active December 21, 2019 07:02
This LiveData provides the time in hh:mm:ss format, updating the value every second
package io.github.yaraki.dependencyinjection
import android.arch.lifecycle.LiveData
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.text.format.DateFormat
import java.util.*
class ClockLiveData : LiveData<CharSequence>() {
package io.github.yaraki.miscex
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
@yaraki
yaraki / LiveDataWithTimeout.kt
Last active September 15, 2020 18:06
LiveData with timeout
/*
* Copyright (C) 2018 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
@yaraki
yaraki / pi.go
Created January 21, 2014 12:22
Ramanujan's formulas of pi in Go
package main
import (
"fmt"
"math"
)
func fact(n float64) float64 {
r := float64(1)
for 1 < n {
@yaraki
yaraki / MainActivity.kt
Last active February 26, 2021 10:22
Just an idea
package com.example.android.codelab.animationdemo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
@yaraki
yaraki / Gap.kt
Created March 5, 2021 05:50
Common interface for Spacers in Column and Row
package com.example.android.codelab.animationdemo.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
@yaraki
yaraki / MainViewModel.kt
Created September 21, 2018 05:12
SharedPreferences as LiveData
package io.github.yaraki.playground
import android.app.Application
import android.arch.lifecycle.AndroidViewModel
import android.content.Context
class MainViewModel(application: Application) : AndroidViewModel(application) {
companion object {
const val PREF = "main"
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun LifecycleEffect(event: Lifecycle.Event, action: () -> Unit) {
val lifecycleOwner = LocalLifecycleOwner.current
val observer = LifecycleEventObserver { _, e ->
if (event == e) {
action()
}