Skip to content

Instantly share code, notes, and snippets.

View GE-N's full-sized avatar

Jerapong Nampetch GE-N

View GitHub Profile
@GE-N
GE-N / FRP iOS Learning resources.md
Created January 3, 2016 13:05 — forked from JaviLorbada/FRP iOS Learning resources.md
The best FRP in iOS links.

Videos

@GE-N
GE-N / struct_and_inheritance.swift
Created October 1, 2015 08:42 — forked from AliSoftware/struct_vs_inheritance.swift
Swift-Struct-Inheritance
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
@GE-N
GE-N / bdd#3-stubfail.swift
Created August 16, 2015 09:51
BDD#3 stub fail
context("Send SMS") {
// Specify API to Stub
let apiSendSMSStub = OHHTTPStubsTestBlock = { request -> Bool in
return request.URL!.path == "/api/sendsms"
}
it("should success") {
...
}
@GE-N
GE-N / bdd#3-stubsuccess.swift
Last active August 29, 2015 14:27
bdd#3 stub success
context("Send SMS") {
// Specify API to Stub
let apiSendSMSStub = OHHTTPStubsTestBlock = { request -> Bool in
return request.URL!.path == "/api/sendsms"
}
it("should success") {
// Result success
let successBlock: OHHTTPStubsResponseBlock = { request -> OHHTTPStubsResponse in
let success200 = "{\"success\": true}".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
@GE-N
GE-N / Credit.swift
Created August 16, 2015 08:50
BDD#3 credit class
class Credit {
var count: Int {
set {
// save newValue of credits to somewhere.
}
get {
return // credits value saved.
}
}
import Foundation
import Quick
import Nimble
import OHHTTPStubs
import SMSME
class SMSAPISpec: QuickSpec {
override func spec() {
describe("API") {
context("Send SMS") {
@GE-N
GE-N / smsapi.swift
Last active August 29, 2015 14:27
smsapi for bdd dev
import Alamofire
enum APIResult {
case Success
case Fail(NSError)
func isSuccess() -> Bool {
switch self {
case .Success: return true
case .Fail: return false
platform :ios, '8.0'
use_frameworks!
target 'SMSME' do
pod 'Alamofire'
end
target 'SMSMETests' do
pod 'Quick', '~> 0.3.1' ## For Swift 1.2
pod 'Nimble'
@GE-N
GE-N / gist:cccc79a478b28f7954f5
Created August 2, 2015 06:35
phone number validate with regexp - BDD on swift
// Phone class part
// Phone.swift
import Foundation
class Phone {
class func validateNumber(number: String) -> Bool {
let pattern = "^(08|09)[0-9]{8}$"
let regexp = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: nil)
@GE-N
GE-N / gist:b39c6daac9fff269440c
Created August 2, 2015 05:58
Validate all pass - BDD on Swift @Medium
// Phone class part
// Phone.swift
import Foundation
class Phone {
class func validateNumber(number: String) -> Bool {
// begin with 08 or 09
let beginValid = number.hasPrefix("08") || number.hasPrefix("09")