Skip to content

Instantly share code, notes, and snippets.

View jknair0's full-sized avatar
🌴
Not On vacation

JayaKrishnan Nair jknair0

🌴
Not On vacation
View GitHub Profile
@jknair0
jknair0 / Coords.kts
Last active April 24, 2019 06:47
zones of UTM coods from LatLng coords
data class LatLng(val latitude: Double,val longitude: Double)
class Utm(val latlng: LatLng){
fun utmLongitudeZone(): Int {
return Math.floor(Math.floor((longitude + 180) / 6)).roundToInt() + 1
}
fun utmLatZone(): Char{
if (latitude < -80) {
@jknair0
jknair0 / .gitignore
Last active April 24, 2019 04:18
Read Coordinates from file and plot
*.txt
@jknair0
jknair0 / Serializer.kt
Last active September 26, 2019 21:08
Wrapper for gson in kotlin
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
open class Serializer() {
val gson: Gson = Gson()
fun <T> toJson(targetObject: T): String {
return gson.toJson(targetObject)
}
@jknair0
jknair0 / PreferenceHelper.kt
Created May 1, 2019 05:14
Wrapper over SharedPreferences
import android.content.SharedPreferences
class PreferenceHelper(private val sharedPreferences: SharedPreferences) {
fun getInt(key: String, defaultValue: Int = 0): Int {
return sharedPreferences.getInt(key, defaultValue)
}
fun getFloat(key: String, defaultValue: Float = 0f): Float {
return sharedPreferences.getFloat(key, defaultValue)
@jknair0
jknair0 / PreferenceHelper.kt
Created May 1, 2019 05:14
Wrapper over SharedPreferences
import android.content.SharedPreferences
class PreferenceHelper(private val sharedPreferences: SharedPreferences) {
fun getInt(key: String, defaultValue: Int = 0): Int {
return sharedPreferences.getInt(key, defaultValue)
}
fun getFloat(key: String, defaultValue: Float = 0f): Float {
return sharedPreferences.getFloat(key, defaultValue)
@jknair0
jknair0 / watermark.kt
Last active May 2, 2019 10:06
Adjust the Google Maps water mark Android
private fun adjustGoogleWaterMark() {
try {
val googleLogo = mapFrame.findViewWithTag<ImageView>("GoogleWatermark")
googleLogo ?: return;
with(googleLogo.layoutParams as RelativeLayout.LayoutParams) {
addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE)
addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0)
addRule(RelativeLayout.ALIGN_PARENT_START, 0)
addRule(RelativeLayout.ALIGN_PARENT_TOP, 0)
addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE)
@jknair0
jknair0 / ReadTestResource.kt
Created May 10, 2019 04:41
Read test resource file
fun readContent(fileNameWithExt: String): String? {
return try {
val classLoader = javaClass.classLoader
val resource = classLoader.getResource(fileNameWithExt)
val file = File(resource.file)
file.readText()
} catch (e: Exception) {
null
}
}
@jknair0
jknair0 / EventLiveData.kt
Created July 2, 2019 08:52
live data that emits only once i.e, events
package com.sensehawk.presentation
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.Observer
import android.support.annotation.MainThread
import java.util.concurrent.atomic.AtomicBoolean
class EventLiveData<T> : MutableLiveData<T>() {
@jknair0
jknair0 / .eslintrc.js
Last active August 5, 2019 06:58
eslintrc for react native
//npm install --save eslint-config-airbnb eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react-redux
module.exports = {
'env': {
'jest': true,
},
'parser': 'babel-eslint',
'parserOptions': {
'sourceType': 'module',
'ecmaVersion': 6,
'ecmaFeatures': {
@jknair0
jknair0 / ObserverExt.kt
Last active August 14, 2019 15:27
non null value emission for android lifecycle observer
import android.arch.lifecycle.Observer
/**
* invokes the [callback] if the observer emits a non-null value.
*/
inline fun <reified T: Any?> nonNullObserver(crossinline callback: (T) -> Unit) : Observer<T> {
return Observer {
callback.invoke(it ?: return@Observer)
}
}