Skip to content

Instantly share code, notes, and snippets.

@hadilq
hadilq / NixOS-guide.md
Last active May 10, 2024 21:54
Encypted LUKS LVM Btrfs Root with Opt-in State on NixOS

I'm trying to follow this guide to install NixOS using Btrfs, LUKS and LVM. The main usage of this page for me will be remembering what I did! My laptop is ASUS ROG GL553VD.

Just downloaded Plasma Desktop, 64bit and create a bootable Flash Drive. Then boot up to NixOS Live CD. Using gparted to create two partitions, One 200MB vfat EFI partittion and the rest of SSD drive will be an encrypted partition.

DISK=/dev/nvme0n1
@hadilq
hadilq / RxViewModelActivitySample.kt
Created February 5, 2020 17:43
RxViewModelActivitySample
class RxViewModelActivitySample : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
val viewModel = ViewModelProvider(this).get(RxViewModelSample::class.java)
(viewModel.stringEmitter.observe()) { testString ->
/* use it here */
@hadilq
hadilq / RxViewModelSample.kt
Created February 5, 2020 17:26
RxViewModelSample
class RxViewModelSample : ViewModel() {
private val publisher = PublishProcessor.create<String>()
private val extendedPublisher = BehaviorProcessor.create<String>().apply { onNext("Test") }
/**
* The value of this emitter would NOT be saved on onSaveInstanceState
*/
val stringEmitter = publisher.toLifecycleAware()
class AlbumFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
...
viewState().observe { state ->
.....
}
}
}
class AlbumsViewModel : BaseViewModel {
private val networkErrorLiveData = BehaviorProcessor.create<Throwable>()
private val openAlbumDetailsLiveEvent = PublishProcessor.create<Album>()
fun albumsLiveData(): Flowable<List<Album>> = albumsLiveData.hide().observeOn(AndroidSchedulers.mainThread())
fun networkErrorLiveData(): Flowable<Throwable> =
networkErrorLiveData.hide().observeOn(AndroidSchedulers.mainThread())
fun postAlbums(albums: List<Album>) {
protected fun <T> Flowable<T>.observe(o: (T) -> Unit) {
RxLifecycleHandler(this@BaseFragment, this, o)
}
@FooScope
class FooBridge @Inject constructor() {
lateinit var parent: ViewGroup
@MainThread
get
@MainThread
set
}
class FooViewHolder(
view: View,
// other needed objects
) : RecyclerView.ViewHolder(view) {
@Inject
constructor(bridge: FooBridge, /* other needed objects to inject by Dagger*/) : this(
bridge.parent.inflate(R.layout.foo),
// other needed objects
)
@FooScope
class BridgeAdapter @Inject constructor(
private val fooProvider: Provider<FooViewHolder>,
// ... other ViewHolder providers
private val bridge: FooBridge
) : PagedListAdapter<Entity, RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
bridge.parent = parent
return fooProvider.get()
fun exampleMethod(foo: Boolean, bar: Boolean, ..., baz: Any?) {
assumeTrue("Message of AssertionError when this assumption is not satisfied", foo)
?.assumeFalse("The same as the above message", bar)
...
?.assumeNotNull("An other message", baz) {
// If all the above assumptions get satisfied then this block will be running.
// Else an Assertion log will be triggered on the proper Appenders.
}
// Add more assumptions for the next block
?.assumeEquals("A message", foo, bar) {