This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// GroupTests.m | |
// | |
// Created by Ray Fix on 3/15/14. | |
// | |
#import <XCTest/XCTest.h> | |
#import "NSArray+Groups.h" | |
@interface GroupTests : XCTestCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testPokerAceOfDiamonds() | |
{ | |
let handsWithAceOfDiamonds = Binomial(n: 51, choose: 4) | |
let allPossibleHands = Binomial(n: 52, choose: 5) | |
let probabilityOfAceOfDiamonds = handsWithAceOfDiamonds / allPossibleHands | |
XCTAssertEqual(probabilityOfAceOfDiamonds, Rational(5,52)) | |
let probabilityOfNoAceOfDiamonds = Rational(1) - probabilityOfAceOfDiamonds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
struct Thing { | |
var arr: [Int] = [] { | |
didSet { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// forward | |
// | |
// Created by Ray Fix on 4/8/15. | |
// Copyright (c) 2015 Pelfunc, Inc. All rights reserved. | |
// | |
#include <iostream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
class Subscription | |
def initialize(created_at:) | |
@created_at = created_at | |
end | |
attr_reader :created_at | |
def months_subscribed | |
((Date.today - created_at.to_date) / 30).round |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TaggedThing<Tag, Thing> { | |
var value: Thing | |
} | |
protocol A {} // Phantom Type | |
protocol B {} // Phantom Type | |
var a = TaggedThing<A, Int>(value: 1) | |
var b = TaggedThing<B, Int>(value: 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// Rather than a generic type with constraints on being a UIView and conforming to Extra | |
// you could do something like this. | |
protocol UIViewConvertable { | |
var uiview: UIView { get } | |
} | |
extension UIView : UIViewConvertable { | |
var uiview: UIView { return self } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)mapObjects:(RKObjectManager*)objectManager | |
{ | |
RKObjectMapping* widgetMapping = [RKObjectMapping mappingForClass:[widget class]]; | |
[widgetMapping mapKeyPath:@"id" toAttribute:@"widgetID"]; | |
[widgetMapping mapAttributes:@"name", @"description", nil]; | |
[widgetMapping mapKeyPath:@"public" toAttribute:@"isPublic"]; | |
[widgetMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"]; | |
[widgetMapping mapKeyPath:@"updated_at" toAttribute:@"updatedAt"]; | |
[objectManager.mappingProvider setMapping:widgetMapping forKeyPath:@"widget"]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RKObjectMapping* channelMapping = [RKObjectMapping mappingForClass:[Channel class]]; | |
// Core data | |
//channelMapping.primaryKeyAttribute = "channelID"; | |
// For now using NSObject derived thing | |
[channelMapping mapKeyPathsToAttributes: | |
@"id", @"channelID", | |
@"created_at", @"createdAt", | |
@"updated_at", @"updatedAt", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestKit allows a great deal of customization and can probably be made to handle most formats. | |
Since I have full control over the server (now), I want to put the onus on the server as much | |
as possible and reduce unnecessary bandwidth. However, I want to keep the RestKit side code | |
as easy, and concise as possible. | |
So suppose I have a set of widget classes with ids and names with standard CRUD operations. | |
I have an index action which could potentially return a large number of widgets and so need | |
to be paginated. Here is one way I thought of. | |
Create Action |
OlderNewer