This file contains 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
// | |
// main.cpp | |
// forward | |
// | |
// Created by Ray Fix on 4/8/15. | |
// Copyright (c) 2015 Pelfunc, Inc. All rights reserved. | |
// | |
#include <iostream> |
This file contains 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
require 'active_support/all' | |
class Subscription | |
def initialize(created_at:) | |
@created_at = created_at | |
end | |
attr_reader :created_at | |
def months_subscribed | |
((Date.today - created_at.to_date) / 30).round |
This file contains 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
struct TaggedThing<Tag, Thing> { | |
var value: Thing | |
} | |
protocol A {} // Phantom Type | |
protocol B {} // Phantom Type | |
var a = TaggedThing<A, Int>(value: 1) | |
var b = TaggedThing<B, Int>(value: 2) |
This file contains 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 | |
// Rather than a generic type with constraints on being a UIView and conforming to Extra | |
// you could do something like this. | |
protocol UIViewConvertable { | |
var uiview: UIView { get } | |
} | |
extension UIView : UIViewConvertable { | |
var uiview: UIView { return self } | |
} |
This file contains 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
//: # Harmonic Oscillator Schrödinger Equation | |
//: | |
//: Numerically Solve for Shrödinger's Equation using the | |
//: Numerov algorithm. This example inspired by Quantum | |
//: Physics for Dummies, Steven Holzner, John Wiley & Sons, Inc. 2013. | |
//: | |
//: Had to increase the delta (step size) and reduce the maximum allowed | |
//: error to make it run in a reasonable amount of time in the playground. | |
//: (This obviously could be solved by switching to [more] compiled code.) | |
//: |
This file contains 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
//: # Harmonic Oscillator Schrödinger Equation | |
//: ## Version 2 | |
//: | |
//: Numerically Solve for Shrödinger's Equation using the | |
//: [Numerov method](https://en.wikipedia.org/wiki/Numerov%27s_method). | |
//: This example inspired by Quantum | |
//: Physics for Dummies, Steven Holzner, Wiley 2013. | |
//: | |
//: This version is thousands of times faster and more | |
//: accurate than my more direct port of the original. It starts with |
This file contains 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
var i = 0 | |
while (i < 10) { | |
print(i) | |
i += 1 | |
} |
This file contains 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
struct MultiArray<Element> { | |
private var data: [Element] // the actual data | |
private var counts: [Int] // the size of each dimension | |
private var offsets: [Int] // multipliers for accessing each dimension quickly | |
private func computeIndex(indices: [Int]) -> Int { | |
precondition(indices.count == counts.count) | |
for (index, count) in zip(indices, counts) { | |
precondition(index >= 0 && index < count) |
This file contains 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
// | |
// Blurring.swift | |
// TransitionDemo | |
// | |
// Created by Ray Fix on 1/7/16. | |
// | |
import UIKit | |
protocol Blurring {} |
This file contains 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
//: # Generic frequencies for SequenceType | |
//: | |
//: Based on a tweet from Airspeed Velocity @airspeedswift | |
//: describing a custom subscript operation that takes | |
//: an initial value if the key is not found. | |
import Foundation | |
extension Dictionary { | |
subscript(key: Key, or initial: Value) -> Value { |