Skip to content

Instantly share code, notes, and snippets.

View ibrahimsn98's full-sized avatar
🐙

İbrahim Süren ibrahimsn98

🐙
View GitHub Profile
@ibrahimsn98
ibrahimsn98 / jwt-expiration.md
Created February 8, 2019 13:18 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@ibrahimsn98
ibrahimsn98 / android-get-apps-adaptive-icons-circle
Created January 27, 2018 21:04
Android - Get aplication's adaptive icons in circle form
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
@ibrahimsn98
ibrahimsn98 / BatchEventOperation.kt
Last active October 2, 2022 10:25
ty-demeter-blog-6
internal class BatchEventOperation : Operation {
override suspend fun operate(demeter: Demeter) {
val events = demeter.eventDataProvider.fetchAwaitingEvents(FETCH_EVENT_SIZE)
...
demeter.eventDataProvider.updateEventStatus(
events = events,
eventStatus = EventStatus.PROCESSING,
@ibrahimsn98
ibrahimsn98 / MealDemeterEventDispatcher.kt
Last active September 19, 2022 09:26
ty-demeter-blog-7
class MealDemeterEventDispatcher @Inject constructor(
@MealDemeter private val demeter: Demeter,
) : EventDispatcher {
override fun report(event: Event) {
val eventData = event.getData().analyticsMap[MealEvent.DEMETER] ?: return
...
when (eventGroup) {
@ibrahimsn98
ibrahimsn98 / DemeterResultReporter.kt
Last active September 19, 2022 07:51
ty-demeter-blog-6
demeter.addEventResultReporter(DemeterResultReporter())
...
class DemeterResultReporter : EventResultReporter {
override fun report(result: Result<String>) {
if (result.isFailure) {
// Report the result
}
@ibrahimsn98
ibrahimsn98 / sample_payload.json
Last active September 18, 2022 13:21
ty-demeter-blog-5
{
"session_id": "...",
"platform": "...",
"timestamp": "...",
"os_version": "...",
"app_version": "...",
"domain": "...",
"channel": "...",
"parameters": {
"event_param1": "...",
@ibrahimsn98
ibrahimsn98 / BatchEventDispatcher.kt
Created September 17, 2022 20:05
ty-demeter-blog-4
LifecycleAwareTimer.Builder()
.interval(DISPATCHER_TIMER_INTERVAL)
.scope(dispatcherScope)
.lifecycleOwner(ProcessLifecycleOwner.get())
.onInterval(this::onInterval)
.build()
@ibrahimsn98
ibrahimsn98 / DemeterInitializer.kt
Created September 17, 2022 19:23
ty-demeter-blog-4
internal class DemeterInitializer : Initializer {
override suspend fun initialize(demeter: Demeter) {
demeter.eventDataProvider.updateEventStatus(EventStatus.AWAITING)
}
}
@ibrahimsn98
ibrahimsn98 / OperationQueue.kt
Created September 17, 2022 18:34
ty-demeter-blog-3
internal class OperationQueue(demeter: Demeter, coroutineScope: CoroutineScope) {
private val queue = Channel<Operation>(BUFFER_SIZE)
init {
queue.receiveAsFlow()
.onEach { operation ->
runCatching {
operation.operate(demeter)
}.onFailure {
@ibrahimsn98
ibrahimsn98 / MealDemeterIncerceptor.kt
Last active September 17, 2022 15:48
ty-demeter-blog-1
class MealDemeterInterceptor @Inject constructor(
private val buildConfigProvider: BuildConfigProvider,
private val buildModelProvider: BuildModelProvider,
) : Demeter.Interceptor {
override suspend fun intercept(parameters: Parameters): Parameters {
val mutableParameters = parameters.toMutableMap()
mutableParameters["os_version"] = buildModelProvider.getBuildVersion()
mutableParameters["app_version"] = buildConfigProvider.getAppVersionName()
mutableParameters["domain"] = DOMAIN