Skip to content

Instantly share code, notes, and snippets.

let google: Provider = .google(clientID: "", clientSecret: "")
google.scopes = ["email", "profile"]
google.authorize(getCode: { code, url in
// prompt user to visit url and enter code
}) { result in
switch result {
case .success(let token):
print(token)
case .failure(let error):
@delba
delba / tupple.swift
Created June 10, 2015 11:26
switch tupple
typealias Result = (value: String?, error: String?)
let result = Result("value", nil)
switch result {
case let (.Some(value), .None):
print(value)
case let (.None, .Some(error)):
print(error)
case let (.Some(value), .None(error)):
@delba
delba / first.swift
Last active August 29, 2015 14:22
Catch conditions
func doSomething(object: AnyObject) {
guard let object = object as? String where object.hasPrefix("hel") else {
return
}
print(object.uppercaseString)
}
doSomething("hello")
@delba
delba / Catch.swift
Last active August 29, 2015 14:22
Typing the throwable errors
func catchAll(name: String?) {
do {
try throwSomething(name)
} catch {
print("An error occured")
}
}
func catchAllWithReference(name: String?) {
do {
@delba
delba / playground.swift
Created June 1, 2015 19:06
Partial application of struct method is not allowed
let names = ["karl", "marc", "john"]
struct SomeStruct {
static func uppercase(name: String) -> String {
return name.uppercaseString
}
func uppercase(name: String) -> String {
return name.uppercaseString
}
@delba
delba / gist:e1abcff65b93429d8347
Created May 21, 2015 17:19
This notice is a courtesy: please fix this problem.
CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Tribe$ cat Cartfile
github "realm/realm-cocoa" == 0.92.3
github "SwiftyJSON/SwiftyJSON" >= 2.1.2
github "Alamofire/Alamofire" >= 1.2
github "onevcat/Kingfisher" >= 1.1.1
github "ankurp/Dollar.swift" >= 3.0.0
github "SnapKit/SnapKit" >= 0.11.0
@delba
delba / AdTableViewCell.swift
Last active August 29, 2015 14:20
MoPub iOS sdk with Swift
import UIKit
class AdTableViewCell: UITableViewCell {
// MARK: Subviews
// Add subviews and constraints...
}
import Foundation
enum Provider: String {
case Vimeo = "Vimeo"
case SoundCloud = "SoundCloud"
}
class Item {
let title: String
let provider: Provider
package main
import (
"fmt"
"sort"
)
type StarredRepository struct {
Repository string
Users []string