Skip to content

Instantly share code, notes, and snippets.

[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 August 29, 2015 14:23
associated types for Brent
protocol Value : Equatable {
}
protocol Smashable {
typealias TargetValue : Value
func valueBySmashingOtherValue<SomeOtherValue : Value>(value: SomeOtherValue) -> TargetValue
}
struct Bar : Value {
}
protocol Value {
}
protocol Smashable {
typealias V : Value
func valueBySmashing​OtherValue​(value: V) -> V
}
struct Bar : Value {
}
@kongtomorrow
kongtomorrow / gist:7fc0cabfb7d23e479633
Created May 1, 2015 01:08
surprising id-like behavior of AnyObject
import Foundation
class Hrm {
@objc func objcFunc() {
}
dynamic func dynamicFunc() {
}
func normalFunc() {
@kongtomorrow
kongtomorrow / gist:f2f7aa2c92d61eadcb72
Created May 1, 2015 01:00
why does this compile?
import Foundation
var backing = NSMutableArray()
func pop()->Int? {
return backing.firstObject.map { $0.integerValue }
}
@kongtomorrow
kongtomorrow / gist:4f6d86bea37db7124a84
Last active August 29, 2015 14:16
templateImageByMappingWhiteToClear:
- (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];
@kongtomorrow
kongtomorrow / gist:43f4b319a2f14c5fe48f
Created January 11, 2015 00:39
protocol and class
import Cocoa
protocol MyProtocol {
func myFunc()
}
class MyView : NSView, MyProtocol {
func myFunc() {
}
}
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)
}
@kongtomorrow
kongtomorrow / gist:c5e3494452e419cbf016
Created December 4, 2014 04:08
Address sanitizer squawkage
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>)
#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) {