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 / AndroidManifest.xml
Created June 3, 2013 13:00
ACTION_MY_PACKAGE_REPLACED 사용하기
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mypackagereplaced"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
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)
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SomeSdk.init(this); // init some SDK, MyApplication is the Context
}
}
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="package.of.MyApplication"
... >
<provider
android:authorities="${applicationId}.yourcontentprovider"
android:name=".YourContentProvider"
android:exported="false" />
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
}) {
...
}
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 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
}
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
}
@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())