Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Prasham Trivedi PrashamTrivedi

🏠
Working from home
View GitHub Profile
@PrashamTrivedi
PrashamTrivedi / React-Redux.md
Created Jul 3, 2018
My notes on React redux and it's usages
View React-Redux.md

Redux

  • Redux is a library that manages states. Based on functional principals it solves a problem of data flow in an interesting way.
  • In an app your data should have a unidirectional flow. The data flows forward, it never comes back.
  • A data with changed properties is not same data (Autovalue), it can be a different copy object.
  • In redux, you pass an action, A reducer listens to action and changes store connects both acion and reducer
  • actoin: Must have a string, can optionaly have any type of payload.
  • reducer: Must return a state, it can never throw error or return undefined thing.
    • In any error case or un-recognized action, it should return previous state passed.
  • store: Allows to subscribe/unsubscribe updates, can read current state at any time and sends actions to reducers
View deploy.gradle
import java.text.DateFormat
import java.text.SimpleDateFormat
import org.gradle.internal.os.OperatingSystem;
task(debugSomething) {
doLast {
println OperatingSystem.properties
}
@PrashamTrivedi
PrashamTrivedi / DbSchema.kt
Last active Mar 26, 2019
Some extension functions with room: Requires Export schema Read this section https://medium.com/google-developers/testing-room-migrations-be93cdb0d975#6872
View DbSchema.kt
import com.squareup.moshi.Json
data class DbSchema(@field:Json(name = "formatVersion") val formatVersion: Int? = 0, @field:Json(
name = "database") val database: Database? = Database())
data class Database(@field:Json(name = "version") val version: Int = 0, @field:Json(name = "identityHash") val identityHash: String? = "", @field:Json(
name = "entities") val entities: List<Entity?>? = listOf(), @field:Json(name = "setupQueries") val setupQueries: List<String?>? = listOf())
@PrashamTrivedi
PrashamTrivedi / CursorDelegate.kt
Created Jan 23, 2018
Handle cursor by delegates
View CursorDelegate.kt
inline fun <T> Cursor.delegate(key: String? = null,
crossinline getter: Cursor.(Int) -> T): ReadOnlyProperty<Any?, T> {
return object : ReadOnlyProperty<Any?, T> {
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
val s = key ?: property.name
return getter(getColumnIndex(s))
}
}
@PrashamTrivedi
PrashamTrivedi / GlideDsl.kt
Created Jan 10, 2018
A rough Idea for using Glide as DSL....
View GlideDsl.kt
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.support.annotation.DrawableRes
import android.support.v4.content.ContextCompat
import android.widget.ImageView
import com.bumptech.glide.DrawableTypeRequest
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.Transformation
import com.bumptech.glide.load.engine.DiskCacheStrategy
@PrashamTrivedi
PrashamTrivedi / DownloadRequest.kt
Last active May 20, 2020
Download File with progress indicator, written in Kotlin with Co-routines
View DownloadRequest.kt
suspend fun downloadFile(url: String,
downloadFile: File,
downloadProgressFun: (bytesRead: Long, contentLength: Long, isDone: Boolean) -> Unit) {
async(CommonPool) {
val request = with(Request.Builder()) {
url(url)
}.build()
val client = with(OkHttpClient.Builder()) {
addNetworkInterceptor { chain ->
@PrashamTrivedi
PrashamTrivedi / LoginActivity.kt
Last active Dec 21, 2017
Files to reproduce databinding error in 3.1.0-alpha06
View LoginActivity.kt
class LoginActivity : AppCompatActivity() {
@Inject lateinit var loginPresenter: LoginPresenter
lateinit var binding: ActivityLoginBinding
val loginViewModel: LoginViewmodel by lazy {
LoginViewmodel()
}
@PrashamTrivedi
PrashamTrivedi / ApiResponse.kt
Last active Feb 21, 2018
Code for blogpost. Koroutines, MVP+VM
View ApiResponse.kt
sealed class ApiResponse<T> {
class Loading<Unit> : ApiResponse<Unit>()
class Nothing<Unit> : ApiResponse<Unit>()
class NoInternet<Unit> : ApiResponse<Unit>()
class ConnectionError<Unit>(val throwable: Throwable, val error: String) : ApiResponse<Unit>()
data class Success<T>(val response: Response<T>,
val data: T? = response.body(),
val headers: Headers? = response.headers()) : ApiResponse<T>()
data class SuccessData<T>(val data: T?) : ApiResponse<T>()
@PrashamTrivedi
PrashamTrivedi / io17Modified.xml
Created Nov 29, 2017
Modified intellij theme for io17, with Font Ligatures, Logcat colors and changed size
View io17Modified.xml
<scheme name="io17" version="142" parent_scheme="Darcula">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2017-11-13T20:44:16</property>
<property name="ide">AndroidStudio</property>
<property name="ideVersion">3.0.0.18</property>
<property name="modified">2017-11-29T13:01:35</property>
<property name="originalScheme">Darcula</property>
</metaInfo>
<option name="EDITOR_FONT_SIZE" value="16" />
@PrashamTrivedi
PrashamTrivedi / Spaniard.kt
Last active Sep 14, 2017
Utils for creating spans with minimum texts
View Spaniard.kt
package com.spaniard
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.CharacterStyle
class Spaniard(val originalString: String) {
var spannableStringBuilder = SpannableStringBuilder(originalString)
You can’t perform that action at this time.