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 / mvi_dependencies.md
Last active September 29, 2019 10:59
dependencies used personally for mvi
implementation 'io.reactivex.rxjava3:rxjava:3.0.0-RC3'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
@jknair0
jknair0 / array_zip.js
Created September 12, 2019 08:50
zip two js arrays
static zip(array1, array2) {
if (!array1 || !array2) return [];
const l1 = array1.length;
const l2 = array2.length;
const minLen = l1 < l2 ? l1 : l2;
const minIndex = minLen > 0 ? minLen - 1 : minLen;
const array1sliced = array1.slice(0, minIndex);
const array2sliced = array2.slice(0, minIndex);
return array1sliced.map((item1, index) => [item1, array2sliced[index]]);
}

Keybase proof

I hereby claim:

  • I am kjknair on github.
  • I am jknair (https://keybase.io/jknair) on keybase.
  • I have a public key ASBA33qo2LCudSeCNN3txFZ2ypDIzn8nkHIIFkk7aRZm2Ao

To claim this, I am signing this object:

@jknair0
jknair0 / mapboxHighLightFeature.kt
Last active September 19, 2019 10:06
highlight a feature in mapbox android
private fun updateScannedFeatures(scannedCodeStatus: List<ScannedCodeStatus>) {
val loadedStyle = mapBoxMap?.style ?: return
val mainSolarTablesLayer = loadedStyle.getLayer(MAIN_SOLAR_TABLES_LAYER_ID) as? FillLayer ?: return
val uidLiteralsArray = scannedCodeStatus.map { it.featureUid }
val stops = uidLiteralsArray.map { Expression.stop(it, Expression.color(Color.RED)) }
mainSolarTablesLayer.setProperties(
PropertyFactory.fillColor(
Expression.match(Expression.get("uid"),
Expression.color(Color.BLACK),
* stops.toTypedArray()
@jknair0
jknair0 / ContextKtExtensions.kt
Last active August 18, 2019 13:10
android context extension functions
inline fun <reified T : AppCompatActivity> Context.startActivity(intentExtras: Intent.() -> Unit = {}) {
startActivity(Intent(this, T::class.java).apply {
this.intentExtras()
})
}
fun Context.inflate(
@LayoutRes layoutRes: Int, root: ViewGroup? = null,
attachToParent: Boolean = false
): View {
@jknair0
jknair0 / Webstorm-Airbnb-Javascript-codeStyle.xml
Created August 15, 2019 10:18 — forked from mentos1386/Webstorm-Airbnb-Javascript-codeStyle.xml
Airbnb inspired Webstorm Javascript CodeStyle
<code_scheme name="Airbnb">
<option name="RIGHT_MARGIN" value="100" />
<option name="HTML_ATTRIBUTE_WRAP" value="4" />
<option name="HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE" value="" />
<option name="HTML_ENFORCE_QUOTES" value="true" />
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
@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)
}
}
@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 / 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 / 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
}
}