Skip to content

Instantly share code, notes, and snippets.

View nubbel's full-sized avatar

Dominique d'Argent nubbel

View GitHub Profile
@nubbel
nubbel / main.go
Last active April 27, 2016 13:51
Go inTransaction usage example
package main
import (
"flag"
"log"
"database/sql"
_ "github.com/lib/pq"
)
//
// SegmentedControl.swift
//
// Created by Dominique d'Argent on 15/06/15.
// Copyright © 2015 Dominique d'Argent. All rights reserved.
//
import UIKit
@IBDesignable
DTDKDisableSymbolCopying = YES
DTDKProvisioningProfileExtraSearchPaths = /Library/Server/Xcode/Data/ProvisioningProfiles
DVTCodesigningAllTheThingsLogLevel = 3
DVTDeviceLogLevel = 3
IDEBuildOperationResultBundlePath = /Library/Server/Xcode/Data/BotRuns/BotRun-ea81d563-4787-46b5-a1ea-7dabd4d300d0.bundle/output/xcodebuild_result.bundle
IDEBuildOperationTimingLogLevel = 2
IDEDerivedDataPathOverride = /Library/Server/Xcode/Data/BotRuns/Cache/d988d2a3-6091-45b5-9eac-0bbe88e2631e/DerivedData
final class Box<T> {
let value: T
init(_ value: T) {
self.value = value
}
}
protocol DataType : Printable {
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
infix operator ??= {
associativity right
precedence 90
assignment
}
func ??=<T>(inout optional: T?, defaultValue: @autoclosure () -> T?) -> T? {
optional = optional ?? defaultValue()
// Interpol.playground
import CoreGraphics
typealias Time = CFTimeInterval
typealias Value = CGFloat
typealias Point = CGPoint
typealias Vector = CGVector
typealias Size = CGSize
typealias Rect = CGRect
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> {
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)
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