Skip to content

Instantly share code, notes, and snippets.

View monday8am's full-sized avatar
🙃
meehh

Angel Anton monday8am

🙃
meehh
View GitHub Profile
@monday8am
monday8am / result_serializer.kt
Last active April 23, 2018 09:48
Result serializer
override fun serialize(src: Result<*, *>?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement? {
return when (src) {
// Ignore Loading or Err states
is Result.Loading -> context?.serialize("")
is Result.Err -> context?.serialize("")
// Thanks God that the original type is passed inside the
// ParameterizedType field.
// It lets us to use it for a real serialization
@monday8am
monday8am / result_deserialization.kt
Last active February 17, 2021 20:34
Result deserialization
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): Result<*, *>? {
return when {
// Is it a JsonObject? Bingo!
json?.isJsonObject == true -> {
// Let's try to extract the type in order
// to deserialize this object
val parameterizedType = typeOfT as ParameterizedType
// Returns an Ok with the value deserialized
@monday8am
monday8am / result.kt
Created April 15, 2018 20:37
Result variant of Either pattern
sealed class Result <out V, out E> {
// Idle state
object Loading : Result<Nothing, Nothing>()
// Operation finished correctly with result saved on value
data class Ok <out V > constructor (val value: V): Result<V, Nothing>()
// Operation finished with error
data class Err <out E> constructor (val error: E): Result<Nothing, E>()
@monday8am
monday8am / resultSerializer.kt
Last active April 20, 2018 16:49
Result serializer empty
class ResultSerializer : JsonSerializer<Result<*, *>>, JsonDeserializer<Result<*, *>> {
override fun serialize(src: Result<*, *>?,
typeOfSrc: Type?,
context: JsonSerializationContext?): JsonElement? {
// TODO
}
override fun deserialize(json: JsonElement?,
typeOfT: Type?,
@monday8am
monday8am / typeHierarchy.kt
Last active April 17, 2018 20:10
TypeHierarchy adapter demostration
val gson = GsonBuilder()
.registerTypeHierarchyAdapter(Result::class.java, ResultSerializer())
.create()
@monday8am
monday8am / delivery_state.swift
Created April 1, 2018 12:37
Delivery state described in Swift
enum DeliveryState: StateType {
case notStarted
case settingUp(appId: AppId,
serviceId: ServiceId,
description: ServiceDescription? = null)
case going(progres: DeliveryProgress)
case idle(reason: Idle)
case failed(error: Error)
case finished(status: ServiceStatus)
@monday8am
monday8am / delivery_state.kt
Created April 1, 2018 12:31
Delivery state described in Kotlin
sealed class DeliveryState: StateType {
object NotStarted: DeliveryState()
data class SettingUp (val appId: AppId,
val serviceId: ServiceId,
val description: ServiceDescription? = null): DeliveryState()
data class Going (val progress: DeliveryProgress): DeliveryState()
data class IsIdle (val reason: Idle): DeliveryState()
data class Failed (val error: Throwable): DeliveryState()
data class Finished (val status: ServiceStatus): DeliveryState()
@monday8am
monday8am / network_middleware.kt
Last active April 1, 2018 11:58
Network Middleware fragment for Unidirectional Flow post.
// This middleware executes the async requests related with the Rest API
internal val networkMiddleware: Middleware<AppState> = { dispatch, state ->
{ next ->
{ action ->
when (action) {
// an async operation is called
is SetDeviceInfo -> { getDeviceDescription(deviceId = action.deviceId,
deviceInfo = action.payload,
dispatch = dispatch) }
export FABRIC_API_TOKEN=1111
export FABRIC_BUILD_SECRET=x1x1x1x1x1
export GITHUB_TOKEN=11xx1x1x1x1
desc "Deploy a new version to the Fabric."
lane :fabric do
# upload to Beta by Crashlytics
crashlytics(
api_token: ENV['FABRIC_API_TOKEN'],
build_secret: ENV['FABRIC_BUILD_SECRET']
)
end