Skip to content

Instantly share code, notes, and snippets.

View chrisschreiner's full-sized avatar

Chris Schreiner chrisschreiner

  • Schpaencoder
  • Oslo, Norway, Europe
View GitHub Profile
@chrisschreiner
chrisschreiner / gist:db32cde87300c0e76017
Created September 5, 2014 08:40
Writing succinct constraints
import Cocoa
struct Constraint {
typealias T = (attribute: CAConstraintAttribute, relativeTo:String, relatedAttribute: CAConstraintAttribute, offset: CGFloat)
let data: T
func create() -> CAConstraint {
let newConstraint: AnyObject! = CAConstraint.constraintWithAttribute(data.attribute, relativeTo: data.relativeTo, attribute: data.relatedAttribute, offset: data.offset)
return newConstraint as CAConstraint
}
import Cocoa
struct Constraint {
typealias T = (attribute: CAConstraintAttribute, relativeTo:String, relatedAttribute: CAConstraintAttribute, offset: CGFloat)
let data: T
func create() -> CAConstraint {
let newConstraint: AnyObject! = CAConstraint.constraintWithAttribute(data.attribute, relativeTo: data.relativeTo, attribute: data.relatedAttribute, offset: data.offset)
return newConstraint as CAConstraint
}
import XCPlayground
import UIKit
import Framework3
XCPSetExecutionShouldContinueIndefinitely()
var r = request(.GET, "http://en.lichess.org/api/user/peropaal")
.response { (request, response, data, error) in
println(request)
println()
import UIKit
import XCPlayground
import Framework2
enum PlayerPerspective {
case Black, White
}
class SampleChessBoardView : UIView {
var margin: CGFloat = 15
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
//Swift 2.0
import Foundation
protocol vcProtocol {
func hidePuzzleMessage()
func showPuzzleMessage()
func prepareBoard()
}
class ViewController: vcProtocol {
@chrisschreiner
chrisschreiner / SceneStateMachine.swift
Last active August 29, 2015 14:14
SceneStateMachine V0.2
//
// SceneStateMachine.swift
// Troup
//
// Created by Chris Patrick Schreiner on 04.02.15.
//
//
import Foundation
import SpriteKit
class ST_Initial: ST_Root {
var selection = NodeSelection()
override var stateName:String {return "Singleselection"}
init(context: PStateMachineContext) {
super.init(context)
}
override func perform(f: FunctionEnum) {
public let findCamelCaseStringsRegex = "([A-Z0-9]+(?=$|[A-Z][a-z0-9])|[A-Z]?[a-z0-9]+)"
public func find(string:String, regex:String) -> [String] {
var r:[String] = []
var sr = string.startIndex..<string.endIndex
let opt = NSStringCompareOptions.RegularExpressionSearch
while !sr.isEmpty {
if let match = string.rangeOfString(regex, options:opt, range:sr) {
r.append(string[match])
sr.startIndex = advance(sr.startIndex, distance(match.startIndex,match.endIndex))
import Foundation
extension String {
func toDouble() -> Double? {
return NSNumberFormatter().numberFromString(self)?.doubleValue
}
}
public struct Place: Printable {
var name: String!