Skip to content

Instantly share code, notes, and snippets.

<?php
class AppModel extends Model {
function afterFind($results)
{
$columnTypes = $this->getColumnTypes();
array_walk_recursive($results, array($this, "iterateRecursion"), $columnTypes);
return $results;
@ghahramani
ghahramani / PageableResolver.kt
Created June 6, 2018 22:13
Support Pageable and Sort type in Webflux
package com.navid.webflux.serializer
import org.springframework.core.MethodParameter
import org.springframework.core.ReactiveAdapterRegistry
import org.springframework.data.web.PageableHandlerMethodArgumentResolver
import org.springframework.stereotype.Component
import org.springframework.util.MultiValueMap
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.web.reactive.BindingContext
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport
@ghahramani
ghahramani / app_build.gradle
Created December 9, 2018 22:02
How to add common libraries into Android modules by defining them in root gradle
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
baseFeature true
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
@ghahramani
ghahramani / ProblemVM.kt
Created July 6, 2019 21:09
This is a simple class which will be converted to a JSON
class ProblemVM(
val url: String,
val message: String,
val status: Int,
val params: MutableMap<String, Any> = HashMap()
) {
fun with(key: String, value: Any): ProblemVM {
params[key] = value
return this
@ghahramani
ghahramani / ExceptionTranslator.kt
Last active July 6, 2019 21:11
Error configuration file
import com.fasterxml.jackson.databind.ObjectMapper
import com.navid.test.creditcard.config.AppConstants.Error.Companion.Url.Companion.INTERNAL_TYPE
import com.navid.test.creditcard.config.error.handler.util.ProblemExceptionHandler
import com.navid.test.creditcard.web.rest.vm.ProblemVM
import org.slf4j.LoggerFactory
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
@ghahramani
ghahramani / ProblemExceptionHandler.kt
Created July 6, 2019 21:16
An interface to for exception handlers
interface ProblemExceptionHandler<T : Throwable> {
fun supports(clazz: Throwable): Boolean
fun generateProblemVM(e: T): ProblemVM
}
@ghahramani
ghahramani / HttpStatusCodeExceptionProblemHandler.kt
Created July 6, 2019 21:18
A handler to convert HttpStatusCodeException to ProblemVM
@Component
class HttpStatusCodeExceptionProblemHandler(private val objectMapper: ObjectMapper) :
ProblemExceptionHandler<HttpStatusCodeException> {
override fun supports(clazz: Throwable): Boolean {
return clazz is HttpStatusCodeException
}
override fun generateProblemVM(e: HttpStatusCodeException): ProblemVM {
val status = e.statusCode
@ghahramani
ghahramani / rabbitmq-autocluster_k8s_persistent.bash
Created July 12, 2019 17:11 — forked from gmr/rabbitmq-autocluster_k8s_persistent.bash
Deploy rabbitmq-autocluster on k8s with persistent storage (EBS)
#!/bin/bash
set -eo pipefail
export KUBE_NAMESPACE=test
export REPLICA_COUNT=3
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1beta1
kind: StatefulSet
@ghahramani
ghahramani / BaseGenericReactiveMongoRepository.kt
Last active January 21, 2020 23:33
Spring Data Default Implementation
@NoRepositoryBean
interface BaseGenericReactiveMongoRepository<T> : ReactiveMongoRepository<T, String> {
fun patch(id: String, fields: Map<String, Any>): Mono<T>
}
class SimpleBaseGenericReactiveMongoRepository<ENTITY>(
private val entityInformation: MappingMongoEntityInformation<ENTITY, String>,
private val template: ReactiveMongoTemplate
) : SimpleReactiveMongoRepository<ENTITY, String>(entityInformation, template),
BaseGenericReactiveMongoRepository<ENTITY> {
private val eventPublisher: ApplicationEventPublisher?
init {
val context = template.converter.mappingContext as MongoMappingContext