Skip to content

Instantly share code, notes, and snippets.

View nubbel's full-sized avatar

Dominique d'Argent nubbel

View GitHub Profile
import Foundation
extension NSURL : StringLiteralConvertible {
class func convertFromStringLiteral(value: String) -> Self {
return self(string: value)
}
class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self {
return self(string: value)
import Foundation
struct Meter {
var value: Double
init(_ value: Double) {
self.value = value
}
var mm: Double { return value * 1000.0 }
infix operator < { associativity left }
func <<T : Comparable>(lhs: T, rhs: T) -> ((T, T) -> Bool, () -> T) -> Bool {
return { (op: (T, T) -> Bool, value: () -> T) in
(lhs < rhs) && op(rhs, value())
}
}
func <<T: Comparable>(lhs: ((T, T) -> Bool, () -> T) -> Bool, rhs: @autoclosure () -> T) -> Bool {
return lhs({$0 < $1}, rhs)
infix operator < { associativity left }
// left-most comparison
func <<T : Comparable>(lhs: T, rhs: T) -> ((T, T) -> Bool, () -> T) -> Bool {
return { (op: (T, T) -> Bool, value: () -> T) in
(lhs < rhs) && op(rhs, value())
}
}
// mid comparisons
func encode<T>(var value: T) -> NSData {
return withUnsafePointer(&value) { p in
NSData(bytes: p, length: sizeofValue(value))
}
}
func decode<T>(data: NSData) -> T {
let pointer = UnsafeMutablePointer<T>.alloc(sizeof(T.Type))
data.getBytes(pointer)
struct TakeSequenceView<Base : SequenceType> : SequenceType {
let base: Base
let n: Int
init(_ base: Base, n: Int) {
self.base = base
self.n = n
}
func generate() -> GeneratorOf<Base.Generator.Element> {
// Interpol.playground
import CoreGraphics
typealias Time = CFTimeInterval
typealias Value = CGFloat
typealias Point = CGPoint
typealias Vector = CGVector
typealias Size = CGSize
typealias Rect = CGRect
infix operator ??= {
associativity right
precedence 90
assignment
}
func ??=<T>(inout optional: T?, defaultValue: @autoclosure () -> T?) -> T? {
optional = optional ?? defaultValue()
class ViewModel
class Attribute
attr_reader :name
attr_accessor :model_value, :view_value
def initialize(name, model_value = :_undefined, view_value = :_undefined)
@name = name
@model_value = model_value
@view_value = view_value
end
final class Box<T> {
let value: T
init(_ value: T) {
self.value = value
}
}
protocol DataType : Printable {