Skip to content

Instantly share code, notes, and snippets.

View fmo91's full-sized avatar

Fernando Martín Ortiz fmo91

View GitHub Profile
@fmo91
fmo91 / SmallestAppDelegate.swift
Created February 27, 2017 01:41
Smallest AppDelegate by using PluggableApplicationDelegate.
import UIKit
import PluggableApplicationDelegate
@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate {
override var services: [ApplicationService] {
return [
LoggerApplicationService()
]
@fmo91
fmo91 / BigAppDelegate.swift
Created February 27, 2017 01:52
A bigger but clean AppDelegate with PluggableApplicationDelegate
import UIKit
import PluggableApplicationDelegate
@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate {
override var services: [ApplicationService] {
return [
PushNotificationsService(),
AnalyticsService(),
@fmo91
fmo91 / StorageAccessor.sol
Created November 2, 2017 16:39
Solidity contracts interoperability
pragma solidity ^0.4.4;
import "./ValueStorage.sol";
contract StorageAccessor {
ValueStorage public valueStorage;
function StorageAccessor(address _valueStorageAddress) public {
valueStorage = ValueStorage(_valueStorageAddress);
const pipe = (...fs) => fs.reduce((f, g) => (x) => g(f(x)));
const mul3 = x => x * 3;
const sum2 = x => x + 2;
pipe(sum2, mul3, mul3)(1); // (1 + 2) * 3 * 3 === 27
// Pipes for promise - based flows
// https://medium.com/@dtipson/more-functional-javascript-reducing-promises-ramda-js-arrow-functions-again-c1f90e0a79d0
const program = (...list) => acc => list.reduce( (acc,fn) => acc.then(fn), Promise.resolve(acc));
@fmo91
fmo91 / BaseOperation.swift
Created March 27, 2018 00:37
Base Operation class for Operation/OperationQueue concurrency pattern in iOS.
// From here https://agostini.tech/2017/07/30/understanding-operation-and-operationqueue-in-swift/
class BaseOperation: Operation {
private var _executing = false {
willSet {
willChangeValue(forKey: "isExecuting")
}
didSet {
didChangeValue(forKey: "isExecuting")
}
@fmo91
fmo91 / withLifecycleDebug.js
Created March 28, 2018 15:53
React HOC that logs debug messages on lifecycle methods
import React, { Component } from 'react';
const { log } = console;
export default (prefix) => (WrappedComponent) => {
const message = text => `[${prefix}] ${text}`;
return class EnhancedComponent extends WrappedComponent {
render() {
@fmo91
fmo91 / Konex.swift
Last active May 30, 2019 05:17
Minimal yet modular and testable networking layer written in Swift 4 over URLSession using Codable, protocol extensions and associatedtypes.
//
// Konex.swift
// Konex
//
// Created by Fernando Ortiz on 24/5/18.
// Copyright © 2018 Fernando Ortiz. All rights reserved.
//
import Foundation
public struct RequestData {
public let path: String
public let method: HTTPMethod
public let params: [String: Any?]?
public let headers: [String: String]?
public init (
path: String,
method: HTTPMethod = .get,
params: [String: Any?]? = nil,
struct User: Codable {
let id: Int
let username: String
}