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
#!/usr/bin/env xcrun swift | |
import Foundation | |
func Zen() -> String? { | |
if let url = NSURL(string: "https://api.github.com/zen"), data = NSData(contentsOfURL: url), zen = NSString(data: data, encoding: NSUTF8StringEncoding){ | |
return zen as String | |
} | |
return nil |
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
#!/bin/sh | |
# Alot of these configs have been taken from the various places | |
# on the web, most 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' |
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
/* | |
Distributed under The MIT License: | |
http://opensource.org/licenses/mit-license.php | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell copies of the Software, and to |
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
extension String { | |
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect { | |
let storage = NSTextStorage(string: self) | |
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height)) | |
let layout = NSLayoutManager() | |
layout.addTextContainer(container) | |
storage.addLayoutManager(layout) | |
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length)) | |
container.lineFragmentPadding = 0.0 | |
let _ = layout.glyphRangeForTextContainer(container) |
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
public struct Error: ErrorType { | |
let source: String; let reason: String | |
public init(_ source: String = __FILE__, _ reason: String) { | |
self.reason = reason; self.source = source | |
} | |
} | |
protocol Contextualizable {} | |
extension Contextualizable { | |
func functionContext(function : String = __FUNCTION__) -> String { |
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
//: Playground - noun: a place where people can play | |
//: Prop 'til you Drop | |
indirect enum Formula : CustomStringConvertible { | |
case Var(String) | |
case Or(Formula, Formula) | |
case And(Formula, Formula) | |
case Imply(Formula, Formula) | |
case BiImply(Formula, Formula) | |
case Negate(Formula) |
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
// | |
// HttpStatusCode.swift | |
// | |
// Created by Zachary Smith on 5/1/15. | |
// Copyright (c) 2015 Zachary Smith. All rights reserved. | |
// | |
import Foundation | |
/** |
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
enum Emoji: String { | |
case Copyright = "\u{00A9}" | |
case Registered = "\u{00AE}" | |
case Bangbang = "\u{203C}" | |
case Interrobang = "\u{2049}" | |
case Tm = "\u{2122}" | |
case InformationSource = "\u{2139}" | |
case LeftRightArrow = "\u{2194}" | |
case ArrowUpDown = "\u{2195}" | |
case ArrowUpperLeft = "\u{2196}" |
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 Cocoa | |
// for-in | |
func checkForIn(array: [Int], dict: [Int: String]) { | |
for num in array where dict[num] != nil { | |
num | |
} | |
} | |
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"]) |
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
class CachedDateFormatter { | |
static let sharedInstance = CachedDateFormatter() | |
var cachedDateFormatters = [String: NSDateFormatter]() | |
func formatterWith(#format: String, timeZone: NSTimeZone = NSTimeZone.localTimeZone(), locale: NSLocale = NSLocale(localeIdentifier: "en_US")) -> NSDateFormatter { | |
let key = "\(format.hashValue)\(timeZone.hashValue)\(locale.hashValue)" | |
if let cachedDateFormatter = cachedDateFormatters[key] { | |
return cachedDateFormatter | |
} |
OlderNewer