Skip to content

Instantly share code, notes, and snippets.

View eofster's full-sized avatar

Alexey Kuznetsov eofster

View GitHub Profile
@eofster
eofster / ReceiptAttributesValidation.m
Created August 8, 2016 12:27
Objective-C version of the receipt attributes validation. Implementation file
#import "ReceiptAttributesValidation.h"
#import "ReceiptChecksum.h"
#import "ReceiptPayload.h"
NS_ASSUME_NONNULL_BEGIN
@interface ReceiptAttributesValidation ()
@property(nonatomic, readonly) id<ReceiptValidation> origin;
@property(nonatomic, readonly) id<ReceiptAttributes> attributes;
@eofster
eofster / ReceiptAttributesValidation.h
Created August 8, 2016 12:26
Objective-C version of the receipt attributes validation. Header file
@import Foundation;
#import "ReceiptValidation.h"
@protocol ReceiptAttributes;
NS_ASSUME_NONNULL_BEGIN
@interface ReceiptAttributesValidation : NSObject <ReceiptValidation>
- (instancetype)initWithOrigin:(id<ReceiptValidation>)origin attributes:(id<ReceiptAttributes>)attributes NS_DESIGNATED_INITIALIZER;
@eofster
eofster / ReceiptAttributesValidation.swift
Last active August 5, 2016 16:31
Swift version of the receipt attributes validation
import Foundation
final class ReceiptAttributesValidation: NSObject {
private let origin: ReceiptValidation
private let attributes: ReceiptAttributes
init(origin: ReceiptValidation, attributes: ReceiptAttributes) {
self.origin = origin
self.attributes = attributes
}
@eofster
eofster / ReceiptAttributesValidation.m
Last active August 8, 2016 12:25
Objective-C version of the receipt attributes validation (in a single .m file)
@import Foundation;
#import "ReceiptChecksum.h"
#import "ReceiptPayload.h"
#import "ReceiptValidation.h"
@protocol ReceiptAttributes;
NS_ASSUME_NONNULL_BEGIN
@eofster
eofster / VendingMachine2.swift
Last active April 25, 2016 09:11
VendingMachine with extracted Inventory
struct Item {
let price: Int
let name: String
var count: Int
}
protocol Inventory {
func itemNamed(name: String) throws -> Item
func remove(item: Item) throws
}
@eofster
eofster / keybase.md
Created April 19, 2016 14:38
Keybase verification

Keybase proof

I hereby claim:

  • I am eofster on github.
  • I am eofster (https://keybase.io/eofster) on keybase.
  • I have a public key ASBLRnkd3pm4-zVlXrNsijcfT-E1LcnumZWjXSrw-yg7xQo

To claim this, I am signing this object:

@eofster
eofster / VendRefactored.swift
Last active April 24, 2016 12:35
Vending machine vend() function refactored
func vend(itemNamed name: String) throws {
let item = try validatedItemNamed(name)
reduceDepositedCoinsBy(item.price)
removeFromInventory(item, name: name)
dispense(name)
}
private func validatedItemNamed(name: String) throws -> Item {
let item = try itemNamed(name)
try validate(item)
@eofster
eofster / VendingMachine.swift
Created December 22, 2015 12:32
Vending machine with long vend() function
struct Item {
var price: Int
var count: Int
}
enum VendingMachineError: ErrorType {
case InvalidSelection
case InsufficientFunds(coinsNeeded: Int)
case OutOfStock
}
@eofster
eofster / CompositionRoot.swift
Created December 15, 2015 15:31
GPS tracker view event handling composition
let viewController = TrackSummaryViewController(
observer: TrackSummaryViewEventHandler(
interactorFactory: InteractorFactoryImpl(repository: TrackRepositoryImpl()),
presenterFactory: PresenterFactoryImpl()
)
)
navigationController.pushViewController(viewController, animated: true)
@eofster
eofster / TrackSummaryViewDummy.swift
Created December 15, 2015 13:23
GPS track summary view dummy
class TrackSummaryViewDummy {}
extension TrackSummaryViewDummy: TrackSummaryView {
func setTrackID(trackID: Int) {}
func setName(name: String) {}
func setDate(date: String) {}
func setDistance(distance: String) {}
}