Skip to content

Instantly share code, notes, and snippets.

View booknara's full-sized avatar

Daehee Han booknara

  • Facebook.Inc
  • San Jose, CA
View GitHub Profile
@booknara
booknara / CoroutineBuilder.kt
Created July 17, 2023 22:17
Launch vs Async in Kotlin Coroutines
package com.booknara.practice.kotlin.coroutine
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
fun main() {
// test_launch()
// test_async()
@booknara
booknara / StructureConcurrency.kt
Created July 17, 2023 17:25
Structure concurrency practice
package com.booknara.practice.kotlin.coroutine
import kotlinx.coroutines.*
/**
* Structure concurrency
* Here are the most important effects of the parent-child relationship:
* children inherit context from their parent(but can also overwrite it)
* a parent suspends until all the children are finished
* when the parent is canceled, its child coroutines are canceled too
@booknara
booknara / JsonConverterTest.kt
Created July 17, 2023 17:24
Json Converter Test using Gson (Json to Object)
package com.booknara.practice.gson
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
class JsonConverterTest {
@booknara
booknara / index.js
Created June 2, 2023 20:50
GraphQL practice using node.js with Apollo Server
const { ApolloServer, gql } = require("apollo-server");
const typeDefs = gql`
scalar Date
"""
An object that describes the chracteristics of a ski day
"""
type SkiDay {
"A ski day unique ID"
@booknara
booknara / BaseResponse.kt
Created May 5, 2023 22:52
It can be used when a network fetch is running/finishing to respond to ViewModel & UI component (Activity or Fragment)
sealed class BaseResponse<out T> {
data class Success<out T>(val data: T? = null): BaseResponse<T>()
data class Loading(val nothing: Nothing? = null): BaseResponse<Nothing>()
data class Error(val msg: String?): BaseResponse<Nothing>()
}
@booknara
booknara / HeroAdapter.kt
Created May 3, 2023 22:56
ListAdapter which has RecyclerView + DiffUtil.ItemCallback
// build.gradle file
// Recycler View (ConcatAdapter)
implementation 'androidx.recyclerview:recyclerview:1.3.0'
// HeroAdapter class
class HeroAdapter(private val context: Context) :
ListAdapter<Hero, HeroAdapter.HeroViewHolder>(HeroDiffCallback) {
private var currentPosition: Int = 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HeroViewHolder {
@booknara
booknara / ViewModelInit.kt
Created April 27, 2023 23:06
How to initialize ViewModel with/without arguments
// Reference: https://dev.to/vtsen/recommended-ways-to-create-viewmodel-or-androidviewmodel-5e7k
// MyViewModel (no argument)
class MyViewModel: ViewModel() {
// Do something
}
// MyAndroidViewModel (Application argument)
class MyAndroidViewModel (app: Application)
: AndroidViewModel(app) {
@booknara
booknara / build.gradle
Last active May 27, 2023 01:39
Android library dependency information
// build.gradle in root folder
buildscript {
ext.hilt_version = '2.46.1'
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
// hilt and kotlin version(org.jetbrains.kotlin.android) should be inter-compatible
plugins {
@booknara
booknara / privacy_policy.md
Created September 20, 2018 23:27
App Analyzer Privacy Policy

Privacy Policy

Daehee Han built the App Analyzer app as a Free app. This SERVICE is provided by Daehee Han at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at App Analyzer unless otherwise defined in this Privacy Policy.

@booknara
booknara / AddDigits.java
Created April 22, 2016 16:56
Add each digit number until the sum value is less than 10
/**
* Created by Daehee Han(@daniel_booknara) on 4/21/16.
*/
public class AddDigits {
public static void main(String[] args) {
int value = 38;
System.out.println(addDigits(value));
}
public static int addDigits(int num) {