Skip to content

Instantly share code, notes, and snippets.

Ken Ferry kongtomorrow

Block or report user

Report or block kongtomorrow

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:c7013b008760abcd4210
[log] V:[a(==b)]
VALID
[log] V:|-(7)-[a]-(7)-|
VALID
[log] V:|-20@750-[a]-10@45-|
VALID
[log] V:|-m-[a(n)]-(>=o)-[b]
Unable to parse constraint format:
Options mask required views to be aligned on a vertical edge, which is not allowed for layout that is also vertical.
V:|-m-[a(n)]-(>=o)-[b]
@kongtomorrow
kongtomorrow / gist:77c53e32ecf50b94f3c1
Last active Aug 29, 2015
associated types for Brent
View gist:77c53e32ecf50b94f3c1
protocol Value : Equatable {
}
protocol Smashable {
typealias TargetValue : Value
func valueBySmashingOtherValue<SomeOtherValue : Value>(value: SomeOtherValue) -> TargetValue
}
struct Bar : Value {
}
View gist:7054ba8094fde4319c43
protocol Value {
}
protocol Smashable {
typealias V : Value
func valueBySmashing​OtherValue​(value: V) -> V
}
struct Bar : Value {
}
@kongtomorrow
kongtomorrow / gist:7fc0cabfb7d23e479633
Created May 1, 2015
surprising id-like behavior of AnyObject
View gist:7fc0cabfb7d23e479633
import Foundation
class Hrm {
@objc func objcFunc() {
}
dynamic func dynamicFunc() {
}
func normalFunc() {
View gist:f2f7aa2c92d61eadcb72
import Foundation
var backing = NSMutableArray()
func pop()->Int? {
return backing.firstObject.map { $0.integerValue }
}
@kongtomorrow
kongtomorrow / gist:4f6d86bea37db7124a84
Last active Aug 29, 2015
templateImageByMappingWhiteToClear:
View gist:4f6d86bea37db7124a84
- (NSImage *)templateImageByMappingWhiteToClear:(NSImage *)image {
NSImage *output = [NSImage imageWithSize:[image size] flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
CGImageRef srcCGImage = [image CGImageForProposedRect:&dstRect context:[NSGraphicsContext currentContext] hints:nil];
CGRect bounds = CGRectMake(0, 0, CGImageGetWidth(srcCGImage), CGImageGetHeight(srcCGImage));
CGContextRef maskCtx = CGBitmapContextCreate(NULL, bounds.size.width, bounds.size.height, 8, 0, CGColorSpaceCreateDeviceGray(), 0);
CGContextDrawImage(maskCtx, bounds, srcCGImage);
CGImageRef mask = CGBitmapContextCreateImage(maskCtx);
CFRelease(maskCtx);
CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
View gist:43f4b319a2f14c5fe48f
import Cocoa
protocol MyProtocol {
func myFunc()
}
class MyView : NSView, MyProtocol {
func myFunc() {
}
}
View gist:ebc9d04c938c999a9ff5
var s : NSString = String(count: n, repeatedValue: Character("."))
let r = NSRegularExpression(pattern: "^(..+?)\\1+$", options: nil, error: nil)!
var l = s.length
var re = [Int]()
while let m = r.firstMatchInString(s, options:nil, range:NSRange(0..<l)) {
let p = m.rangeAtIndex(1).length
re += [p]
l /= p
s = s.substringToIndex(l)
}
View gist:c5e3494452e419cbf016
ken@Nepheli-20 /tmp>
~/bin/clang/bin/clang -O3 -g -fsanitize=address -isysroot /Volumes/Data/Users/ken/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -framework Foundation /tmp/asanBarf.m
ken@Nepheli-20 /tmp> ./a.out
=================================================================
==91531==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00010caf8f1f at pc 0x00010caf8dc2 bp 0x7fff531077a0 sp 0x7fff53107798
READ of size 32 at 0x00010caf8f1f thread T0
#0 0x10caf8dc1 (/private/tmp/./a.out+0x100000dc1)
#1 0x10caf8de4 (/private/tmp/./a.out+0x100000de4)
#2 0x7fff8cdc25c8 (/usr/lib/system/libdyld.dylib+0x35c8)
#3 0x0 (<unknown module>)
View gist:3e35d926ec17d9b621c1
#import <Foundation/Foundation.h>
#import <mach/mach_time.h>
#import <simd/simd.h>
NSTimeInterval SecondsFromMachTimeInterval(uint64_t machTimeInterval) {
static double timeScaleSeconds = 0.0;
if (timeScaleSeconds == 0.0) {
You can’t perform that action at this time.