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 CountableClosedRange { | |
var randomElement: Element { | |
let distance = self.distance(from: startIndex, to: endIndex) | |
let offset = arc4random_uniform(UInt32(distance)) | |
return self[index(startIndex, offsetBy: Bound.Stride(offset))] | |
} | |
} | |
enum Random { |
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
### Keybase proof | |
I hereby claim: | |
* I am msanders on github. | |
* I am mkskm (https://keybase.io/mkskm) on keybase. | |
* I have a public key whose fingerprint is 879D 9776 6369 9CBB 5225 A842 A4EC D720 95C1 EA72 | |
To claim this, I am signing this object: |
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 | |
extension UIImage { | |
convenience init?(uncachedName name: String) { | |
let deviceScale: Double = Double(UIScreen.mainScreen().scale) | |
let scaleFactors = [1.0, 2.0, 3.0].sort { x, y -> Bool in | |
let distanceA = abs(x - deviceScale) | |
let distanceB = abs(y - deviceScale) | |
return distanceA == distanceB ? x > y : distanceA < distanceB | |
} |
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 | |
final class GCDLock<Value> { | |
var value: Value | |
let queue = DispatchQueue(label: "") | |
init(value: Value) { | |
self.value = value | |
} | |
func read() -> Value { |
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
// | |
// ArbitraryExtensions.swift | |
// InstaShopper | |
// | |
// Created by Michael Sanders on 6/18/16. | |
// Copyright © 2016 Instacart. All rights reserved. | |
// | |
import Curry | |
import Mockingjay |
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 Nimble | |
import Quick | |
import SwiftCheck | |
final class StringTransformSpec: QuickSpec { | |
override func spec() { | |
describe("chopPrefix<Int>") { | |
it("should remove prefix of given length") { | |
property("result is of expected length") <- forAll { (string: String) in |
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 | |
import Mapper | |
protocol Archivable: Mappable { | |
func encode(archive: Archiver) | |
} | |
final class Archiver { | |
private var mapping: [String: AnyObject] = [:] | |
required init(_ object: Archivable) { |
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/Foundation.h> | |
int main() { | |
NSNumber *a = @1; | |
NSNumber *b = @2; | |
NSNumber *c = @200; | |
NSLog(@"%d", a < b); // Prints 1 (true) | |
NSLog(@"%d", a < c); // Prints 1 (true) | |
} |
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 click | |
def set_global_domain(ctx, param, value): | |
if value: | |
ctx.params["domain"] = "NSGlobalDomain" | |
return value | |
@click.group() | |
def cli(): | |
pass |
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 sh | |
# From http://collectiveidea.com/blog/archives/2014/02/18/a-simple-pair-programming-setup-with-ssh-and-tmux/ | |
set -eu | |
HELP=false | |
for flag in "$@"; do | |
case "$flag" in | |
-h|--help) HELP=true;; | |
esac | |
done |