Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

View GitHub Profile
@jarsen
jarsen / gist:8887833
Last active August 29, 2015 13:56
Cool AppCode Keymappings
My stuff is all based off the Xcode keymap—it helps you start with a little bit of familiarity.
Run is weird in appcode, cause it doesn't hit the breakpoints like Xcode's run does. What you want is Debug.
I have mapped Debug to ⌘+R, and Debug... to ⌘+⇧+R (Debug... is awesome!) (Also if you hold shift when you are in the Debug... menu you can run instead of debug)
I have remapped ⌘+T to Class... Effectively this allows me to open new tabs a la Sublime style where you hit command t for a new tab, and then enter the class name you want to open in that tab.
I don't like a lot of the ⌘+1 through ⌘+9 windows the way they are. I picked the ones I like and then remapped them to the lower keys for the ones I like to use a lot. I also hid all the tool window bars.
var animals = ["cow", "dog", "pig"]
var emoji = ["🐮", "🐶", "🐷"]
for (animal, pic) in Zip2(animals, emoji) {
println("\(animal) \(pic)")
}
extension Array {
func each (block : (T) -> ()) {
for item in self {
block(item)
}
}
}
animals.each(println)
@jarsen
jarsen / NSURLStringCrap.swift
Last active August 29, 2015 14:02
Add string literal to NSURL
extension NSURL : StringLiteralConvertible {
public class func convertFromStringLiteral(value: String) -> Self {
return self(string: value)
}
public class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self {
return self(string: value)
}
}
@jarsen
jarsen / TinyWebOO.swift
Created June 12, 2014 19:17
TinyWeb program designed to run in a playground. Adapted from the OO java example in Functional Programming Patterns in Scala and Clojure (Pragmatic Bookshelf)
// TinyWeb OOP(ish) Style
import Foundation
class HTTPResponse {
let body: String
let responseCode: Int
init(body: String, responseCode: Int) {
self.body = body
@jarsen
jarsen / enumcrap.swift
Created August 15, 2014 17:27
Making an enum out of your own classes. Not sure if this is a great idea, but it works and is cool.
class Name : StringLiteralConvertible, Equatable {
var firstName: String
var lastName: String
required init(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
}
class func convertFromStringLiteral(value: StringLiteralType) -> Self {
@jarsen
jarsen / error.swift
Last active August 29, 2015 14:05
Exploring error patterns in swift
enum Fallible<T> {
case Error(NSError)
case Some(T)
init(value: T) {
self = .Some(value)
}
init(error: NSError) {
self = .Error(error)
@jarsen
jarsen / take.swift
Created September 5, 2014 19:42
infinite sequences via generators & take
class EvenNaturalNumbers: SequenceType {
typealias GeneratorType = EvenNaturalNumbersGenerator
func generate() -> EvenNaturalNumbersGenerator {
return EvenNaturalNumbersGenerator()
}
}
class EvenNaturalNumbersGenerator : GeneratorType {
var current = 2
@jarsen
jarsen / PotentialFields.swift
Last active August 29, 2015 14:06
Potential Fields in Swift
// Playground - noun: a place where people can play
import UIKit
typealias Vector2D = (x: Float, y: Float)
typealias Point2D = Vector2D
func -(lhs: Vector2D, rhs: Vector2D) -> Vector2D {
return (lhs.x - rhs.x, lhs.y - rhs.y)
}
@jarsen
jarsen / mse.swift
Last active August 29, 2015 14:07
how can I bind to a tuple in the closure?
func meanSquaredError(predictions: [Double], values: [Double]) -> Double {
let sum = reduce(Zip2(predictions, values), 0.0) { (acc, y) in
let diff = y.0 - y.1
return acc + (diff * diff)
}
return sum / Double(predictions.count)
}
// what I want is to bind the arguments in the closure to (acc, (yHat, y))