Skip to content

Instantly share code, notes, and snippets.

View pokk's full-sized avatar
🌀

Jieyi pokk

🌀
View GitHub Profile
@pokk
pokk / README.md
Created October 25, 2016 06:12
Create a service running on background mode.

Intrduction

Keep a service running on background mode in iOS.

@pokk
pokk / README.md
Last active November 9, 2020 11:14
Kotlin stdlib "let", "run", "apply", "also", "use", "with"

[TOC]

Introduction

There are very good five stdlib operates we can use.

  1. let
  2. run
  3. apply
  4. also
@pokk
pokk / README.md
Last active July 23, 2018 06:59
Redirect file stdin in PyCharm

Introduction

For Pycharm IDE, we want to use redirect input file while running the code.

How to Use

  1. You can make a file for a input data as like *.in.
  2. Typing auto_redirect_input_file.py in top of code.
  3. Click the "Edit Configuration".
  4. Put the file name *.in in "Script parameters".
@pokk
pokk / README.md
Created January 13, 2017 07:51
using kotlin language in new instance.

Introduction

New a fragment instance in Kotlin style.

artistAdapter = ArtistAdapter(this@fragment, R.layout.item_artist_type_1, artistRes) { holder, item, _ ->
// !! The problem will happen here.
// The ViewModel will be created again and again.
holder.binding.avm = RecyclerViewSearchArtistChartViewModel(item)
}
@pokk
pokk / MvvmModifiedAdapter.kt
Last active January 16, 2018 15:34
the adapter was fixed.
artistAdapter = ArtistAdapter(this@ChartIndexFragment, R.layout.item_artist_type_1, artistRes) { holder, item, _ ->
// If a ViewModel doesn't exist, I will create a ViewModel.
if (null == holder.binding.avm)
holder.binding.avm = RecyclerViewSearchArtistChartViewModel(item)
// Otherwise, I just reset the data to the ViewModel.
else
holder.binding.avm?.setArtistItem(item)
}
class ActivityModule {
@Provides
@PerActivity
fun provideNavigator(): Navigator = Navigator()
@Provides
@PerActivity
fun provideMainPresenter(): MainContract.Presenter = MainPresenter()
}
@Singleton
@Component(modules = arrayOf(AppModule::class))
interface AppComponent {
object Initializer {
fun init(app: App): AppComponent = DaggerAppComponent.builder()
.appModule(AppModule(app))
.netModule(NetModule(app))
.build()
}
@pokk
pokk / OldApp.kt
Last active December 3, 2017 02:42
class App: Application() {
companion object {
lateinit private var context: Context
@JvmStatic fun appComponent(): AppComponent = (context as App).appComponent
// Provide the global application context.
@JvmStatic fun getAppContext(): Context = context
}
// Before dagger 2.11
@pokk
pokk / AppModule.kt
Last active December 3, 2017 02:38
app module for my blog.
@Module
class AppModule {
@Provides
@Singleton
fun provideApplication(app: App): Application = app
@Provides
@Singleton
fun provideAppContext(app: App): Context = app.applicationContext
}