Skip to content

Instantly share code, notes, and snippets.

View brentsimmons's full-sized avatar

Brent Simmons brentsimmons

View GitHub Profile
//
// VSTagAuthority.h
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
/*
//
// VSTagAuthority.m
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
#import "VSTagAuthority.h"
#import "VSTag.h"
//
// VSTagAuthoritySQL.h
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
//
// VSTagAuthoritySQL.m
// Vesper
//
// Created by Brent Simmons on 2/28/14.
// Copyright (c) 2014 Q Branch LLC. All rights reserved.
//
#import <libkern/OSAtomic.h>
#import "VSTagAuthoritySQL.h"
@brentsimmons
brentsimmons / gist:5ccd357f0fa1486bdc3f
Created July 20, 2015 03:23
Class is unknown until runtime
// How do you do this in Swift?
- (Class)classToUse {
return [Foo class]; // assume it's something else sometimes
}
- (id)generateThingForString:(NSString *)s {
Class thingClass = [self classToUse];
return [[thingClass alloc] initWithString:s];
}
@brentsimmons
brentsimmons / gist:2080595ac8a6f41711af
Last active August 29, 2015 14:25
Swift init from unknown class
import Cocoa
protocol Thing {
var x: String {get}
init(s: String)
}
class Foo: Thing {
let x: String
@brentsimmons
brentsimmons / PointerEquality.swift
Last active August 29, 2015 14:25
Protocols and pointer equality
//: Playground - noun: a place where people can play
import Cocoa
// Solution: if I use "class" instead of "AnyObject", then it’s a pure Swift solution:
// http://inessential.com/2015/07/23/swift_diary_3_arrays_protocols_and_p
// https://twitter.com/_mattrubin/status/624266521896992768
// Or… AnyObject may be marked @objc, but it is in fact a native Swift feature:
// https://twitter.com/jckarter/status/624270700614942721
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
@objc protocol Thing {
func doThing(x: String) throws -> String
}
//: Playground - noun: a place where people can play
import Cocoa
var aSet = Set<Int>()
aSet.insert(1)
aSet.insert(2)
aSet.insert(3)
// The rest of this code doesn't even remotely work.
@brentsimmons
brentsimmons / allstatus.rb
Created January 1, 2012 04:25
Find Mercurial repositories and print status
#!/usr/bin/env ruby -wKU
# Prints the directory names and hg status output for any Mercurial
# repositories where hg status returns something non-nil.
#
# Assumes everything is in a Projects directory in your home folder.
# 12/31/2011 Brent Simmons
require 'find'
require 'open3'