Hi, I’m Sam

This is my blog. I also have a website thing.

Network Testing in Swift with DVR

Posted on

Networking testing is hard. There’s a few approaches. The most common I’ve seen is stubbing requests. OCMock is a common approach.

Personally, I’ve never been a fan of mocks and stubs. At some point you just end up testing your mocks and stubs instead of your real code. When it comes to testing, I want unit tests to test logic and integration tests to test compositions.

I think focusing on testing everything in isolation isn’t great. If you have stuff that is hard to test in isolation, either it should be redesigned to more encapsulated or due to the nature of it, you need to test it at a higher level.

Continue reading →

SyntaxKit

Posted on

I sat down to work on Whiskey the other day and go super side tracked. I have this new master plan to greatly improve Whiskey's markdown parsing, but it's a lot of work so I started procrastiworking. I noticed some bugs in SyntaxKit, what I wrote so Whiskey can do code coloring for things other than Markdown, and decided to start fixing them. Because I was procrastiworking, the logical first step was to rewrite it in Swift 2 :)

Since this isn't terribly specific to Whiskey, I decided to open source SyntaxKit. It makes TextMate-style syntax highlighting easy. It works on iOS & OS X. There aren't any dependencies besides system frameworks. Boom.

Carthage is the recommended way to install SyntaxKit. Add the following to your Cartfile:

Continue reading →

Automatic UI Updates with Value Types in Swift

Posted on

Value types are one of my favorite things in Swift. At first, I was resistant. It’s a much different way of thinking. Let’s look at a simple example that really shows the power.

I was recently working on a little control for entering in numbers on Apple Watch. Here's the code:

public struct NumberPad: Printable {

    // MARK: - Properties

    public var value: Double

    public let decimalPlaces: UInt

    public var description: String {
        let formatter = NSNumberFormatter()
        formatter.numberStyle = .CurrencyStyle
        formatter.maximumFractionDigits = Int(decimalPlaces)
        formatter.minimumFractionDigits = currencyFormatter.maximumFractionDigits
        return formatter.stringFromNumber(value)!
    }

    public var isEmpty: Bool {
        return value == 0.0
    }


    // MARK: - Initializers

    public init(value: Double = 0.0, decimalPlaces: UInt = 2) {
        self.value = value
        self.decimalPlaces = decimalPlaces
    }


    // MARK: - Manipulation

    public mutating func insert(place: Int) {
        let offset = pow(10.0, Double(decimalPlaces))
        var int = Int(value * offset)
        int *= 10
        int += place
        value = Double(int) / offset
    }

    public mutating func deleteBackwards() {
        let offset = pow(10.0, Double(decimalPlaces))
        var int = Int(value * offset)
        int /= 10
        value = Double(int) / offset
    }
}
Continue reading →

Redacted for Mac Launch

Posted on

Yesterday, Redacted for Mac hit the App Store. It's this little app I've been working on here and there to quickly hide parts of an image. Here's a one minute video demo if you want the quick rundown.

All I did was tweet the video about it a few days before it came out and then tweeted that it was out early the morning it was ready. Someone else submitted it to Product Hunt after seeing my tweet. The results were pretty shocking!

For launch, the price was $4.99. I may play with that some over time. I was originally thinking $2.99 and a bunch of folks on Twitter said $4.99 was better. Anyway, Redacted was #8 top paid in the US and #1 top paid in Graphics at the end of launch day. It was also at the top of Product Hunt with 538 up votes! Wow!

Continue reading →

Desk Headphones

Posted on

Recently, I replaced the headphones I've had for a long time with some new ones. I've used Beyerdynamic DT 770 for years (now discontinued). On a flight last year, someone leaned the chair back in front of me suddenly, the cable got caught, and the jack bent really bad. They cut in out a lot. I realize I could just replace the jack, but I thought it was a good excuse to go nuts.

My whole setup with new headphones, case, DAC, preamp, and cables was a little under $400 (half for the headphones and half for all of the toys). You could definitely just get the headphones for $200.

If you're looking for something on the cheap, I recommend a pair of Sony MDR7506. Standard issue studio headphones. Can't go wrong for only $70.

Continue reading →