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 / MainViewModel.kt
Created September 28, 2018 07:24
FPS as LiveData (with coroutine)
/*
* 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 / 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 / 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"
@yaraki
yaraki / fluent.kt
Created July 11, 2018 13:07
Fluent testing for Kotlin in Japanese
package io.github.yaraki.superfluent
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.greaterThan
import org.junit.Test
class Sample {
@yaraki
yaraki / CreateLiveData.kt
Created July 9, 2018 06:44
LiveData + Kotlin Coroutines
package io.github.yaraki.coroutineex
import android.arch.lifecycle.LiveData
import android.content.Context
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.SendChannel
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
@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>() {
@yaraki
yaraki / main_activity.xml
Last active June 25, 2018 05:51
Place an icon at the end of a "wrap_content" text view
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
@yaraki
yaraki / gc.c
Created September 14, 2017 12:44
Simple GC
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef enum _Type Type;
enum _Type {
TYPE_INT,
TYPE_PAIR,
};
@yaraki
yaraki / CheckerView.java
Created February 20, 2017 07:06
Android View that shows a dummy checkered pattern
/*
* Copyright (C) 2017 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 / BottomSheetModal.java
Created February 25, 2016 10:11
Modal Bottom Sheet
/*
* Copyright (C) 2015 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