Skip to content

Instantly share code, notes, and snippets.

Daniel Martín danielmartinprieto

Block or report user

Report or block danielmartinprieto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danielmartinprieto
danielmartinprieto / ReactNavigation+Context.js
Last active Oct 9, 2019
React Navigation Navigator wrapped in a React Context Provider
View ReactNavigation+Context.js
// So we have a context...
const Context = React.createContext();
class Provider extends React.Component {
addTodo = todo => this.setState(({ todos }) => ({ todos: [...todos, todo] }));
state = {
todos: [],
addTodo: this.addTodo
@danielmartinprieto
danielmartinprieto / AsyncReSwift.swift
Last active Nov 14, 2017
Swift Playground showcasing the use of ReSwift middleware to perform asynchronous operations, in contrast of other possible approaches.
View AsyncReSwift.swift
import UIKit
import PlaygroundSupport
import ReSwift
// API
protocol API {
func loadUsers(completion: @escaping (([User]) -> Void))
}
@danielmartinprieto
danielmartinprieto / ProducerConsumer.swift
Created Mar 6, 2017
Producer-consumer written in Swift
View ProducerConsumer.swift
// Note you can copy this code andn paste it in a Xcode Playground
// Simulates working and introduces some randomness
func randomSleep() {
sleep(arc4random_uniform(2))
}
// Item to be produced/consumed
struct Item {
let id: Int
View ReduceExample.swift
func arrayToTuple(array: [Int]) -> (Int, Int, Int) {
return array.reduce((0, 0, 0)) { temp, item in
switch item {
case 0..<10: return (temp.0 + 1, temp.1, temp.2)
case 10..<100: return (temp.0, temp.1 + 1, temp.2)
default:
return item > 100 ? (temp.0, temp.1, temp.2 + 1) : temp
}
}
}
@danielmartinprieto
danielmartinprieto / gist:fdb81a8e28c1b414b85d
Last active Aug 29, 2015
AppDelegate to run unit tests faster in Swift.
View gist:fdb81a8e28c1b414b85d
1. Comment out @UIApplicationMain in your AppDelegate.
2. Create main.swift file with the following code:
import Foundation
import UIKit
let isRunningTests = NSClassFromString("XCTestCase") != nil
if isRunningTests {
You can’t perform that action at this time.