Skip to content

Instantly share code, notes, and snippets.

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

Umut ADALI kobeumut

🏠
Working from home
View GitHub Profile
@kobeumut
kobeumut / check_data_size_on_list.dart
Last active October 7, 2021 12:30
This extension is used when the list is unknown. So if the list is empty or the calling position is not available, shows an error which is Index out of range or null point exception. This extension provides easy usage to get data.
extension CheckData on List? {
T getItem<T>(int position,{dynamic errorReturnValue = "."}) => (this?.length ?? 0) > position ? this![position] : errorReturnValue;
}
//USAGE
// var list = [1,2,5,7];
// print("${list[4]}"); this shows index out of range error so now you can use like below
// list.getItem(4) it's return dot because of the default errorReturnValue is .
//
// if you want specify the error value you can enter errorReturnValue parameter
@kobeumut
kobeumut / ApplicationExecutors.java
Created August 1, 2021 11:26
It can be used instead of coroutines in small projects
public class ApplicationExecutors {
private final Executor background;
private final Executor mainThread;
public Executor getBackground() {
return background;
}
public Executor getMainThread() {
@kobeumut
kobeumut / ViewExt.kt
Created November 22, 2020 08:33
Find View with tag recursively in Kotlin
fun ViewGroup.findViewWithTagRecursively(tag: Any): List<View>? {
val allViews: MutableList<View> = ArrayList<View>()
val childCount: Int = this.childCount
for (i in 0 until childCount) {
val childView: View = this.getChildAt(i)
if (childView is ViewGroup) {
childView.findViewWithTagRecursively(tag)?.let { allViews.addAll(it) }
} else {
val tagView: Any? = childView.tag
if (tagView != null && tagView == tag) allViews.add(childView)
@kobeumut
kobeumut / DateExtension.kt
Created August 12, 2020 20:58 — forked from maiconhellmann/DateExtension.kt
Date extensions wrote in Kotlin
import java.text.SimpleDateFormat
import java.util.*
/**
* Pattern: yyyy-MM-dd HH:mm:ss
*/
fun Date.formatToServerDateTimeDefaults(): String{
val sdf= SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
return sdf.format(this)
}
@kobeumut
kobeumut / Extension.kt
Created June 3, 2020 19:50
Save file extension with retrofit and coroutine
Call<ResponseBody>.saveFile(fileNameWithExt: String, action: (file: File?) -> Unit) {
GlobalScope.launch {
try {
cacheDir.listFiles { _, name -> name.contains("${fileType}.pdf") }?.lastOrNull {
action(it)
true
}?:
withContext(Dispatchers.IO) {
val response = this@saveFile.execute()
val buffer = response.body()?.byteStream()
fun alternateMerge(arr1: IntArray, arr2: IntArray,
n1: Int, n2: Int, arr3: IntArray) {
var i = 0
var j = 0
var k = 0
// Traverse both array
while (i < n1 && j < n2) {
arr3[k++] = arr1[i++]
arr3[k++] = arr2[j++]
}
@kobeumut
kobeumut / .gitlab-ci.yml
Created October 30, 2019 18:55
deploy rails with ssh
before_script:
- apt-get update -qq
- apt-get install -qq git
##
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
##
[
{ "code":"AF", "country" : "Afghanistan", "bound": [60.53, 29.32, 75.16, 38.49] },
{ "code":"AO", "country" : "Angola", "bound": [11.64, -17.93, 24.08, -4.44] },
{ "code":"AL", "country" : "Albania", "bound": [19.3, 39.62, 21.02, 42.69] },
{ "code":"AE", "country" : "United Arab Emirates", "bound": [51.58, 22.5, 56.4, 26.06] },
{ "code":"AR", "country" : "Argentina", "bound": [-73.42, -55.25, -53.63, -21.83] },
{ "code":"AM", "country" : "Armenia", "bound": [43.58, 38.74, 46.51, 41.25] },
{ "code":"AQ", "country" : "Antarctica", "bound": [-180.0, -90.0, 180.0, -63.27] },
{ "code":"TF", "country" : "French Southern Territories", "bound": [68.72, -49.78, 70.56, -48.63] },
{ "code":"AU", "country" : "Australia", "bound": [113.34, -43.63, 153.57, -10.67] },
@kobeumut
kobeumut / setup_digitalocean_rails.md
Created May 10, 2019 06:04 — forked from newmetl/setup_digitalocean_rails.md
Setup a Droplet on Digital Ocean for Rails with Nginx, Passenger and Postgresql

Setup new Server

This setup guide was created with the following components:

  • DigitalOcean Droplet (Ubuntu 16.04.4 x64)
  • Postgresql 9.5
  • Nginx + Passenger
  • Rails 5.2
  • Ruby 2.4.1
@kobeumut
kobeumut / ObserveOnceExtension.kt
Created April 21, 2019 08:24
Android Livedata Observe Once Only (Kotlin)
fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, observer: Observer<T>) {
observe(lifecycleOwner, object : Observer<T> {
override fun onChanged(t: T?) {
observer.onChanged(t)
removeObserver(this)
}
})
}
//Using
liveData.observeOnce(this, Observer<Password> {