Skip to content

Instantly share code, notes, and snippets.

View jungilhan's full-sized avatar
🏠
Working from home

Jungil Han jungilhan

🏠
Working from home
View GitHub Profile
@jungilhan
jungilhan / ktx.json
Last active January 21, 2022 02:23
ktx
{"schemaVersion":1,"label":"ktx","message":"1.0.0-rc12","color":"yellow"}
@jungilhan
jungilhan / MainActivity.kt
Last active May 22, 2018 22:50
SelectionTracker.Builder
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
selectionTracker = SelectionTracker.Builder(
"selection-demo",
recyclerView,
StableIdKeyProvider(recyclerView),
itemDetailsLookup,
StorageStrategy.createLongStorage())
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Int>() {
override fun areItemsTheSame(oldItem: Int?, newItem: Int?) =
oldItem == newItem // check uniqueness
override fun areContentsTheSame(oldItem: Int?, newItem: Int?) =
oldItem == newItem // check contents
}
class MainActivity : AppCompatActivity() {
private val numbersObservable: BehaviorSubject<List<Int>>
= BehaviorSubject.createDefault(listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
override fun onCreate(savedInstanceState: Bundle?) {
...
swipeRefreshLayout.setOnRefreshListener {
numbersObservable.onNext(listOf(1, 2, 4, 5, 6, 7, 8, 9)) // pass a new list without 0, 3
}
class NumberViewHolder(parentView: View) : RecyclerView.ViewHolder(
LayoutInflater.from(parentView.context).inflate(R.layout.card_item, null, false)) {
private val numberView = itemView.findViewById<TextView>(R.id.number)
fun bindTo(position: Int) {
numberView.text = "# $position"
}
}
class NumberListAdapter : ListAdapter<Int, ViewHolder>(object : DiffUtil.ItemCallback<Int>() {
override fun areItemsTheSame(oldItem: Int?, newItem: Int?) =
oldItem == newItem // check uniqueness
override fun areContentsTheSame(oldItem: Int?, newItem: Int?) =
oldItem == newItem // check contents
}) {
...
}
<provider
android:authorities="${applicationId}.yourcontentprovider"
android:name=".YourContentProvider"
android:exported="false" />
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="package.of.MyApplication"
... >
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SomeSdk.init(this); // init some SDK, MyApplication is the Context
}
}
import cv2
import numpy as np
img = cv2.imread('sudoku.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (7, 7), 0)
thresh = cv2.adaptiveThreshold(gray, 255, 1, 1, 7, 2)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)