Skip to content

Instantly share code, notes, and snippets.

View d-ronnqvist's full-sized avatar

David Rönnqvist d-ronnqvist

View GitHub Profile
@d-ronnqvist
d-ronnqvist / gist:7ea8b1dc7d10f23917c2
Created December 10, 2014 20:04
I'm designing something where there are multiple different objects that can hold exactly _one_ out of a couple of different other types, and I don't know what style I prefer.
// I'm designing something where there are multiple different objects that can hold
// exactly _one_ out of a couple of different other types, and I don't know what style I prefer.
//
// For example, an Input always has a name and it can hold a Symbol, a Target, or a Texture.
// It should always hold exactly one of them. In just the same way, a Symbol has a name and can
// hold different data of exactly exactly _one_ type of many.
//
// Which one of the following alternatives do you prefer?
@d-ronnqvist
d-ronnqvist / Hexagon Ripple.swift
Created December 22, 2014 19:48
Hexagon Ripple in a Swift Playground
import AppKit
import QuartzCore
import XCPlayground
// Parameters that define the style
let hexSideLength: CGFloat = 15.0
let hexLineWidth: CGFloat = 3.0
let colors = [NSColor.redColor(), NSColor.cyanColor(), NSColor.greenColor(), NSColor.yellowColor(), NSColor.redColor()].map { $0.CGColor }
@d-ronnqvist
d-ronnqvist / gist:22f40a2f52f48ccf7e89
Created May 7, 2015 12:40
Drawing a clipped gradient beyond the start and end points
import Foundation
import UIKit
class MyView: UIView {
override func drawRect(rect: CGRect) {
// just some path
let path = UIBezierPath(roundedRect: CGRectMake(10, 10, 200, 100), byRoundingCorners: .TopLeft | .BottomRight, cornerRadii: CGSizeMake(30, 60))
// fill with red
UIColor.redColor().setFill()