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
// Proving 2x2 = 4 without numbers | |
indirect enum set: Equatable { | |
case empty | |
case notEmpty(element: set, rest: set = .empty) | |
static func == (lhs: set, rhs: set) -> Bool { | |
switch (lhs, rhs) { | |
case (.empty, .empty): return true | |
case (_, .empty): return 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
import UIKit | |
class MyTextLabel: UIView { | |
var textLayer = CATextLayer() | |
var textStorage: String = "" { | |
didSet { | |
textLayer.string = textStorage | |
} | |
} |
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 RandomAccessCollection { | |
func random() -> Iterator.Element? { | |
guard count > 0 else { return nil } | |
let offset = arc4random_uniform(numericCast(count)) | |
let i = index(startIndex, offsetBy: numericCast(offset)) | |
return self[i] | |
} | |
} |
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
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol" |
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 scala.collection._ | |
import scala.collection.generic.CanBuildFrom | |
import scala.collection.mutable.{Builder, MapBuilder} | |
case class Word(value: String) extends AnyVal | |
class WordMap extends PrefixMap[Word] | |
class PrefixMap[T] | |
extends mutable.Map[String, T] |
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
class PrefixMatcher { | |
private var set = new scala.collection.immutable.TreeSet[String]() | |
private def successor(s: String) = s.take(s.length - 1) + (s.charAt(s.length - 1) + 1).toChar | |
def add(s: String) = set += s | |
def findMatches(prefix: String): Set[String] = | |
if (prefix.isEmpty) set | |
else set.range(prefix, successor(prefix)) | |
} |
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 | |
final class MasonaryFlowLayout: UICollectionViewFlowLayout { | |
override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { | |
guard let attrs = super.layoutAttributesForItemAtIndexPath(indexPath) else { return nil } | |
if indexPath.item == 0 { | |
return attrs | |
} |
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
func hashValue<T: Hashable>(objects: T?...) -> Int { | |
var result = 31 | |
for object in objects { | |
result = (result &* 17) &+ object.hashValue | |
} | |
return result | |
} | |
func hashValue<T: Hashable>(objects: T...) -> Int { | |
var result = 31 |
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
return jsonBuilder() | |
.startObject() | |
.startObject(TYPE_NAME) | |
.startObject("properties") | |
.startObject("id") | |
.field("type", "string") | |
.field("index", "not_analyzed") | |
.endObject() | |
.startObject("title") | |
.field("type", "string") |
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
// | |
// RootViewController.swift | |
// Filters | |
// | |
// Created by Haldun Bayhantopcu on 03/03/16. | |
// Copyright © 2016 Haldun Bayhantopcu. All rights reserved. | |
// | |
import UIKit |
NewerOlder