Skip to content

Instantly share code, notes, and snippets.

View hasanmohdkhan's full-sized avatar
💭
Rocking life with code 💻💻

Hasan Mhad Khan hasanmohdkhan

💭
Rocking life with code 💻💻
View GitHub Profile
@hasanmohdkhan
hasanmohdkhan / setprop.sh
Created September 9, 2022 09:50 — forked from kongchen/setprop.sh
set properties file value by key via bash shell
#!/bin/bash
############################
#script function
############################
setProperty(){
awk -v pat="^$1=" -v value="$1=$2" '{ if ($0 ~ pat) print value; else print $0; }' $3 > $3.tmp
mv $3.tmp $3
}
############################
@hasanmohdkhan
hasanmohdkhan / grokking_to_leetcode.md
Created June 29, 2022 04:18 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

@hasanmohdkhan
hasanmohdkhan / sniff.txt
Created December 16, 2021 03:02 — forked from manifestinteractive/sniff.txt
A friendly formatter for curl requests to help with debugging.
\n
============= HOST: ==========\n
\n
local_ip: %{local_ip}\n
local_port: %{local_port}\n
remote_ip: %{remote_ip}\n
remote_port: %{remote_port}\n
\n
======= CONNECTION: ==========\n
\n
@hasanmohdkhan
hasanmohdkhan / version.gradle
Created March 29, 2021 06:10 — forked from aldiand/version.gradle
Gradle Version
/*
* 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
@hasanmohdkhan
hasanmohdkhan / .gitignore
Created January 15, 2021 08:59
git ignore file for Android Studio
#built application files
*.apk
*.ap_
*.aab
# files for the dex VM
*.dex
# Java class files
*.class
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
#parse("File Header.java")
#project level
build.gradle
dependencies {
//...
classpath "com.google.dagger:hilt-android-gradle-plugin:${version_hilt}
//...
}
#Module level
build.gradle
@hasanmohdkhan
hasanmohdkhan / CustomViewModelFactory.kt
Created July 7, 2020 21:10 — forked from adam-hurwitz/SomeFragment.kt
Optimizing ViewModel with Lifecycle 2.2.0: Passing Arguments/Parameters with SavedState
class SomeViewModelFactory(
private val owner: SavedStateRegistryOwner,
private val defaultArgs: Bundle,
private val someString: String) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, state: SavedStateHandle) =
SomeViewModel(state, someString) as T
}
class SomeViewModel(private val state: SavedStateHandle, private val someString: String) : ViewModel() {
// The default value is used from 'defaultArgs' since 'defaultArgs' are saved in the ViewModelFactory.
@hasanmohdkhan
hasanmohdkhan / CustomViewModelFactory.kt
Created July 7, 2020 21:06 — forked from adam-hurwitz/SomeFragment.kt
Optimizing ViewModel with Lifecycle 2.2.0: Passing Arguments/Parameters
// Override ViewModelProvider.NewInstanceFactory to create the ViewModel (VM).
class SomeViewModelFactory(private val someString: String): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel?> create(modelClass: Class<T>): T = SomeViewModel(someString) as T
}
class SomeViewModel(private val someString: String) : ViewModel() {
init {
//TODO: Use 'someString' to init process when VM is created. i.e. Get data request.
}
}
@hasanmohdkhan
hasanmohdkhan / Fragment.kt
Created July 7, 2020 20:58 — forked from adam-hurwitz/Fragment.kt
Optimizing ViewModel with Lifecycle 2.2.0: Declaring VM val
class Fragment : Fragment() {
private val viewModel: SomeViewModel by viewModels()
private fun observeViewState() {
viewModel.viewState.observe(viewLifecycleOwner) { viewState ->
//viewState used here.
}
}
}