Skip to content

Instantly share code, notes, and snippets.

@seivan
seivan / gitflow-breakdown.md
Created August 5, 2016 12:27 — forked from JamesMGreene/gitflow-breakdown.md
A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
git commit --allow-empty -m "Initial commit"
git checkout -b develop master

Connect to the remote repository

@seivan
seivan / version.sh
Created July 20, 2016 12:56 — forked from osteslag/version.sh
Script for managing build and version numbers using git and agvtool. See link in comments below.
#!/bin/sh
# Script for managing build and version numbers using git and agvtool.
# Change log:
# v1.0 18-Jul-11 First public release.
# v1.1 29-Sep-12 Launch git, agvtool via xcrun.
version() {
@seivan
seivan / firstDifferenceBetweenStrings.swift
Created July 7, 2016 11:41 — forked from kristopherjohnson/firstDifferenceBetweenStrings.swift
Swift code to find differences between strings and display them in a readable way, useful for displaying unit test results
import Foundation
/// Find first differing character between two strings
///
/// :param: s1 First String
/// :param: s2 Second String
///
/// :returns: .DifferenceAtIndex(i) or .NoDifference
public func firstDifferenceBetweenStrings(s1: NSString, s2: NSString) -> FirstDifferenceResult {
@seivan
seivan / erase.swift
Last active June 11, 2016 16:59
try this
struct ExpressionErased : Chainable {
var chainType: SQLiteChainType = .None
let __andOperator:((rhs:Chainable) -> [Chainable])
init<T : Chainable>(expression:T) {
self.__andOperator = expression.andOperator
}
func andOperator(rhs: Chainable) -> [Chainable] {
return self.__andOperator(rhs: rhs)
class Pub {init?(){}};
let zoo = false ? Pub() : nil
func bar() -> Pub? { return nil };
let boo = false ? bar() : nil
func foo() -> Pub { return Pub()! };
let poo = false ? foo() : nil // can't
let keys = [
1 : ["value" : "FirstValue", "dependencies" : Set(arrayLiteral: 2)],
2 : ["value" : "SecondValue", "dependencies" : Set(arrayLiteral: 1)],
]
keys.reduce(Dictionary<Set<Int>, Set<Int>>()) { (allDependencies, keyValueTuple) in
let (key, content) = keyValueTuple
var dependencyGraph = allDependencies
let dependencyKey = (content["dependencies"] as! Set<Int>).union([key])
func crap<T>(arg:T) {
print(String(T))
print(String(arg))
print(Mirror(reflecting: arg))
print(Mirror(reflecting: arg).subjectType)
print(String(Mirror(reflecting: arg)))
print(String(Mirror(reflecting: arg).subjectType))
}
@seivan
seivan / temp-fix.swift
Last active June 7, 2016 18:48
Doesn't help with the "temp" variables not being passed over, but allows flatMap to work like Swift 3.
extension CollectionType {
private func flatMap<S : SequenceType>(transform: (Self.Generator.Element) throws -> S) rethrows -> Set<S.Generator.Element> {
return
Set(
try self
.map(transform)
.filter { $0 != nil }
.map { $0! }
.flatten()
)
@seivan
seivan / lexer.swift
Created June 5, 2016 14:00 — forked from radex/lexer.swift
Wrote a little lexer/tokenizer for fun. (Warning: I have no idea what I'm doing)
import Foundation
struct Stream {
let string: NSString
var position: Int
var matchingRange: NSRange {
return NSRange(location: position, length: string.length - position)
}
}
@seivan
seivan / responder-chain.swift
Created June 2, 2016 07:27 — forked from RoyalIcing/responder-chain.swift
Responder chain in Swift using enums
//: Responder chain in Swift using enums
protocol CommandProtocol {}
protocol Responder: class {
var nextResponder: Responder? { get }
func performerForCommand
<Command : CommandProtocol>
(command: Command) -> (() -> ())?