This file contains hidden or 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 Foundation | |
extension NSDate { | |
convenience init(year: Int, month: Int, day: Int) { | |
let now = NSDate() | |
let calendar = NSCalendar.currentCalendar() | |
let components = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: now) | |
components.year = year | |
components.month = month | |
components.day = day |
This file contains hidden or 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
extension String { | |
enum TruncationPosition { | |
case Head | |
case Middle | |
case Tail | |
} | |
func truncated(limit: Int, position: TruncationPosition = .Tail, leader: String = "...") -> String { | |
guard self.characters.count > limit else { | |
return self |
This file contains hidden or 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 Pokemon { | |
let name: String | |
} | |
let pokemons: [Pokemon] = [ | |
Pokemon(name: "Bulbasaur"), | |
Pokemon(name: "Ivysaur"), | |
Pokemon(name: "Venusaur"), | |
Pokemon(name: "Charmander"), | |
Pokemon(name: "Charmeleon"), |
This file contains hidden or 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 | |
struct Lens<A, B> { | |
private let getter: A -> B | |
private let setter: (A, B) -> A | |
init(getter: A -> B, setter: (A, B) -> A) { | |
self.getter = getter | |
self.setter = setter | |
} |
This file contains hidden or 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 XCPlayground | |
import UIKit | |
struct Pokemon { | |
let id: UInt | |
let name: String | |
} | |
class PokedexViewController: UITableViewController { | |
let pokemons: [Pokemon] = [ |
This file contains hidden or 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
extension Dictionary { | |
func merged(another: [Key: Value]) -> Dictionary { | |
var result: [Key: Value] = [:] | |
for (key, value) in self { | |
result[key] = value | |
} | |
for (key, value) in another { | |
result[key] = value | |
} | |
return result |
This file contains hidden or 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
extension ErrorType { | |
var errorSummary: String { | |
return "" | |
} | |
} | |
extension NSError { | |
var errorSummary: String { | |
return localizedDescription | |
} |
This file contains hidden or 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
#!/bin/sh | |
id="com.example.yourapp" | |
dir=$HOME/Library/Developer/Xcode | |
mv $dir/Products $dir/Products.orig && \ | |
mkdir $dir/Products && \ | |
cp -R $dir/Products/$id $dir/Products/ |
This file contains hidden or 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
#!/usr/bin/env ruby | |
files = `git diff --cached --name-only | grep .rb`.split | |
exit 0 if files.empty? | |
ok = true | |
files.each do |file| | |
next unless File.exist?(file) | |
result = system "rubocop", "--auto-correct", file | |
ok = false if result == false |
This file contains hidden or 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
#!/bin/sh | |
rubocop --auto-correct `git diff --cached --name-only | grep .rb` |