Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃
meehh

Angel Anton monday8am

🙃
meehh
View GitHub Profile
@monday8am
monday8am / combineReducers.kt
Created Mar 31, 2019
CombineReducer method in Kotlin
View combineReducers.kt
//
// Reducer interface definition
//
typealias Reducer<ReducerStateType> = (action: Action, state: ReducerStateType?) -> ReducerStateType
//
// Combine reducers method
//
fun<T: StateType> combineReducers(vararg reducers: Reducer<T>): Reducer<T> {
return { action, state ->
@monday8am
monday8am / create_signed_app.ruby
Created Jan 13, 2019
Create signed Android app. Fastlane + Gradle
View create_signed_app.ruby
desc "Create a signed version of the app"
lane :signed_apk do
# get version and build number from git
# https://blog.uncommon.is/using-git-to-generate-versionname-and-versioncode-for-android-apps-aaa9fc2c96af
versionName = sh("git describe --dirty").gsub(/\s+/, "")
# +520 to sync version codes with the previous app.
versionCode = sh("git rev-list --first-parent --count origin/master").gsub(/\s+/, "").to_i + 520
keyPath ="#{sh("pwd").chomp}/keystore.jks"
@monday8am
monday8am / RxCBCentralManagerExample.swift
Last active Jan 7, 2019
Example of how to use the RxCBCentralManager utility
View RxCBCentralManagerExample.swift
// Creates the Rx version of the API passing the same parameters as the system version
let centralManager: RxCBCentralManager = RxCBCentralManager(queue: DispatchQueue.main, options: nil)
// Creates a Rx pipe using the published methods
centralManager.scanForPeripherals(withServices: [requiredServiceUIDD], options: nil)
.filter { (peripheral: CBPeripheral) -> Bool in
if let name = peripheral.name {
return name.contains("peripheralName")
}
return false
@monday8am
monday8am / RxCBCentralManager.swift
Last active Jan 7, 2019
Rx implementation for CBCentralManager API
View RxCBCentralManager.swift
/**
Lightweight Rx wrapper to CBCentralManager
to hide all implementation details.
*/
public class RxCBCentralManager {
// system API manager
private let centralManager: CBCentralManager
// internal delegate
private let internalDelegate = InternalDelegate()
private var lastConnectedDevice: CBPeripheral?
View middleware_kotlin.kt
internal val deviceMiddleware: Middleware<AppState> = { dispatch, state ->
// dispatch: Function that send actions to the begining of the middleware list
// state: Function that returns an atomic copy of the state
// next: Function to send the action to the next middleware
// action: New incoming action
{ next ->
{ action ->
when (action) {
is DeviceConnected -> {
val currentState = state()?.appStoreState
@monday8am
monday8am / action_creator.swift
Last active Oct 10, 2018
Simple action creator in Swift
View action_creator.swift
// Action creator definition
func fetchAppsFromStore(state: State, store: Store<State>) -> Action? {
let request = AppStoreRequests.apps(showDevelopment: state.settingsState.isDevelopmentMode)
let task = JsonRequestTask<[AppId]>(dispatcher: dispatcher)
// Async task call
task.perform(request)
.subscribe(onNext: { result in
@monday8am
monday8am / async_seudo_code.swift
Last active Jul 29, 2018
Async seudo code call
View async_seudo_code.swift
if state.needsAsyncData {
dispatch(LoadingAction)
asyncCall()
.whenOk { dispatch(OkAction(result) }
.whenError { dispatch(ErrorAction(error)) }
}
@monday8am
monday8am / ResultSerializer.kt
Created Apr 20, 2018
Original Fidesmo Result JsonSerializer
View ResultSerializer.kt
package com.fidesmo.devicemanager.helpers
import com.google.gson.*
import com.google.gson.internal.LinkedTreeMap
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.lang.reflect.WildcardType
class ResultSerializer : JsonSerializer<Result<*, *>>, JsonDeserializer<Result<*, *>> {
@monday8am
monday8am / Result.kt
Created Apr 20, 2018
Original Result.kt from Fidesmo code
View Result.kt
package com.fidesmo.devicemanager.helpers
// Based on https://github.com/danneu/kotlin-result
typealias NetworkResult<V, E> = Result<V, E>
fun <V, E> Result<V, E>.getOrElse(default: V) = when (this) {
is Result.Ok<V> -> value
is Result.Err<E> -> default
is Result.Loading -> default
View result_serializer.kt
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
You can’t perform that action at this time.