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 optional_pair1<T,U>(t: T?, u: U?)->String { | |
switch (t,u) { | |
// every case exhaustively covers the possibilities | |
case (.None,.None): return "neither" | |
case let (.Some(t), .Some(u)): return "both" | |
case let (.Some(t),.None): return "left" | |
case let (.None,.Some(u)): return "right" | |
// so no need for a default clause at all | |
// this way, you are totally explicit about | |
// which case is being handled how. |
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
class Position | |
attr_reader :x, :y | |
@cache_of_positions = {} | |
def self.new_with_memo(x,y) | |
@cache_of_positions[[x,y]] || Position.new(x,y).tap do |instance| | |
@cache_of_positions[[x,y]] = instance | |
end | |
end |
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
<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
<meta charset="UTF-8"> | |
<style> | |
.cell{ | |
width:50px ; | |
height:50px; | |
padding: 0px; |
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
development: | |
adapter: postgresql | |
encoding: unicode | |
database: url_development | |
pool: 5 | |
username: jd | |
password: | |
host: localhost | |
port: 5432 | |
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
// SegueInteractor.swift | |
// SegueIdentifier enumerates just the segue ID strings in the storyboard. VC's don't switch on this... | |
private enum SegueIdentifier: String { | |
case ShowDetail | |
} | |
// SegueInteractor binds closures to segues. VC's switch on this instead! | |
enum SegueInteractor { | |
case PrepareShowDetail((EventEntity) -> Void) |
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
------------ | |
Conformances | |
------------ | |
protocol AbsoluteValuable | |
Conformances: | |
Comparable | |
IntegerLiteralConvertible | |
SignedNumberType |
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 sumRecursively(numbers: [Int], _ acc:Int = 0) -> Int { | |
if let head = numbers.first { | |
let tail = Array(dropFirst(numbers)) | |
return sumRecursively(tail, head + acc) | |
} else { | |
return acc | |
} | |
} | |
let myNumbers = [1,2,3,4,5] |
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
public protocol Selfie: CustomStringConvertible {} | |
extension Selfie { | |
var description: String { | |
let mirror = Mirror(reflecting: self) | |
return "\(mirror.subjectType)( \(mirror.children.map({ "\($0!): \($1) "}).joinWithSeparator(", ")))" | |
} | |
} |
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
// | |
// shuffle.swift | |
// | |
// Created by Guillaume Lessard on 2014-08-28. | |
// Copyright (c) 2016 Guillaume Lessard. All rights reserved. | |
// | |
// https://github.com/glessard/shuffle | |
// https://gist.github.com/glessard/7140fe885af3eb874e11 | |
// |
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 User { | |
let id: Int | |
let name: String | |
let email: String? | |
} | |
extension User: JSONDecodable { | |
static func create(id: Int, name: String, email: String?) -> User { | |
return User(id: id, name: name, email: email) | |
} |
OlderNewer