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
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 |
public class ApplicationExecutors { | |
private final Executor background; | |
private final Executor mainThread; | |
public Executor getBackground() { | |
return background; | |
} | |
public Executor getMainThread() { |
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) |
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) | |
} |
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 = [email protected]() | |
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++] | |
} |
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] }, |
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> { |