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 Foundation | |
struct FilteringGenerator<T where T:Generator> : Generator { | |
let test:(T.Element) -> Bool | |
var generator:T | |
init(_ generator:T, _ test: (T.Element) -> Bool) { | |
self.test = test | |
self.generator = generator | |
} |
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 Foundation; | |
@interface PrimeEnumerator : NSObject<NSFastEnumeration> | |
- (NSArray *)knownPrimes; | |
@end | |
@interface PrimeEnumerator () | |
@property (nonatomic, strong) NSMutableArray *primes; | |
@end |
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
// Good idea or Bad idea? | |
// Lets say you have to call some API with lots of parameters that you don't control | |
// Like this http://developer.android.com/reference/android/text/StaticLayout.html#StaticLayout(java.lang.CharSequence, int, int, android.text.TextPaint, int, android.text.Layout.Alignment, float, float, boolean, android.text.TextUtils.TruncateAt, int) | |
// Do you prefer Option #1 or Option #2? Is Option #2 a terrible idea? | |
// I suppose Option #3 could be to wrap it in a Builder | |
class Foo { |
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 | |
struct PartialConstraint { | |
private let item:AnyObject | |
private let attribute:NSLayoutAttribute | |
private let multiplier:CGFloat? | |
private let constant:CGFloat? | |
private func constraintWith(partial:PartialConstraint, relation:NSLayoutRelation) -> NSLayoutConstraint { | |
assert(multiplier == nil && constant == nil, "Cannot define multiplier or constant on LHS.") |
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/python | |
# fix-xcode | |
# Rob Napier <robnapier@gmail.com> | |
# Script to link in all your old SDKs every time you upgrade Xcode | |
# Create a directory called /SDKs (or modify source_path). | |
# Under it, put all the platform directories: | |
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform | |
# Under those, store the SDKs: |
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/swift | |
import Foundation | |
let url = NSURL(string: "http://not-a-real-host")! | |
let request = NSURLRequest(URL: url) | |
var response:NSURLResponse? = nil | |
var error:NSError? = nil | |
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error) |
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
<meta name="viewport" content="initial-scale=1, maximum-scale=1"> | |
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<style> | |
div { | |
position: absolute; | |
background-color:green; | |
left: 100px; | |
} |
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/swift | |
// TL;DR: Skip to line 183. | |
// To run as a script, run with /usr/bin/swift or chmod +x. | |
// To run as a playground, comment out the first line and `mkdir -p "~/Documents/Shared Playground Data"`. | |
import Foundation | |
let stdin = NSFileHandle.fileHandleWithStandardInput() | |
let stdout = NSFileHandle.fileHandleWithStandardOutput() |
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/swift | |
// Because sometimes you don't want to crop. | |
// USAGE: aspect-grow RATIO FILES... | |
// aspect-grow 4:6 *.jpg | |
// | |
// Places all files in an output directory relative to their location, so | |
// aspect-grow 4:6 *.jpg creates a folder "output" in this directory but | |
// aspect-grow 4:6 a/b.jpg and b/c.jpg creates folders a/output and b/output. |
OlderNewer