Skip to content

Instantly share code, notes, and snippets.

Avatar
🐝
I may be slow to respond.

Faruk Toptaş faruktoptas

🐝
I may be slow to respond.
View GitHub Profile
View BaseBindingListAdapter.kt
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.support.annotation.IdRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
abstract class BaseBindingListAdapter<T, in DB : ViewDataBinding> : RecyclerView.Adapter<BaseBindingListAdapter<T, DB>.BaseViewHolder>() {
View MrzValidator.kt
object MrzValidator {
private val COEFFICIENTS = listOf(7, 3, 1)
private const val EMPTY = '<'
/**
* Samples:
* - Document number: isValid("D123456785", 0, 9) actual document number is "D12345678" check character is "5"
* - Date: isValid("7903063", 0, 6)) actual date is "790306" check character is "3"
*/
@faruktoptas
faruktoptas / debounce.kt
Created Mar 5, 2020
Kotlin coroutine debounce for EditText
View debounce.kt
fun <T> debounce(
waitMs: Long = 300L,
scope: CoroutineScope,
destinationFunction: (T) -> Unit
): (T) -> Unit {
var debounceJob: Job? = null
return { param: T ->
debounceJob?.cancel()
debounceJob = scope.launch {
delay(waitMs)
View vs_shortcuts.txt
1.Code formatting
On Windows: Shift + Alt + F
On Mac: Shift + Option + F
On Ubuntu: Ctrl + Shift + I
2.Copy line up/down
On Windows: Shift + Alt + Up/Down
On Mac: Shift + Option + Up/Down
On Ubuntu: Ctrl + Shift + Alt + Up/Down
@faruktoptas
faruktoptas / bash.sh
Last active Sep 10, 2019
Git commands
View bash.sh
#Switch to dev branch, pull it then come back to my current branch
current="$(git branch | grep \* | cut -d ' ' -f2)";git checkout dev;git pull origin dev;git checkout $current
@faruktoptas
faruktoptas / renew.sh
Created Jan 30, 2019
Script to renew letsencrypt certificate
View renew.sh
echo "1/7 Stopping nginx"
sudo service nginx stop
echo "2/7 Removing mongod.lock"
rm /var/lib/mongodb/mongod.lock
echo "3/7 Stopping mongod"
sudo service mongod stop
echo "4/7 Renewing letsencrypt"
@faruktoptas
faruktoptas / data_binding.kt
Last active Aug 2, 2019
DataBinding samples
View data_binding.kt
// Conditional string
android:text="@{viewModel.startButtonText ? @string/title_start_travel : @string/title_start}"
// Conditional visibility
<import type="android.view.View" />
android:visibility="@{viewModel.visibility == 1 ? View.VISIBLE : View.GONE}"
// Non-string text
android:text="@{String.valueOf(data.minutes)}"
@faruktoptas
faruktoptas / build.gradle
Created Nov 11, 2018
Useful gradle commands
View build.gradle
// Depenency graph
./gradlew -q dependencies app:dependencies
@faruktoptas
faruktoptas / tfs-find-user-tasks.js
Last active Apr 5, 2019
Merge same tasks for different team members into one task. Generate a clean/printable board
View tfs-find-user-tasks.js
var USER = "USER"
var json = document.getElementById("taskboard").innerHTML.split("</script>");
var data = JSON.parse(json[0].substring(55, json[0].length))
function contains(list, item){
var has = false
list.forEach(function(l){
if (l == item){
has = true
}
@faruktoptas
faruktoptas / gen.py
Created Sep 22, 2018
Generate Android/iOS localization files from a JSON file
View gen.py
import sys,json,os, collections
infile = 'res.json'
def __main__():
if (len(sys.argv) < 3):
print "Usage: \npython gen.py [android | ios] outfile"
sys.exit()
type = sys.argv[1]
if (type != "android" and type != "ios" ):
You can’t perform that action at this time.