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
protocol Value { | |
} | |
protocol Smashable { | |
typealias V : Value | |
func valueBySmashingOtherValue(value: V) -> V | |
} | |
struct Bar : 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
import Foundation | |
var backing = NSMutableArray() | |
func pop()->Int? { | |
return backing.firstObject.map { $0.integerValue } | |
} | |
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
- (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]; |
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 Cocoa | |
protocol MyProtocol { | |
func myFunc() | |
} | |
class MyView : NSView, MyProtocol { | |
func myFunc() { | |
} | |
} |
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
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) | |
} |
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
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>) |
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> | |
#import <mach/mach_time.h> | |
#import <simd/simd.h> | |
NSTimeInterval SecondsFromMachTimeInterval(uint64_t machTimeInterval) { | |
static double timeScaleSeconds = 0.0; | |
if (timeScaleSeconds == 0.0) { |
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
Compiled with: | |
~/bin/clang/bin/clang -O3 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize -isysroot /Volumes/Data/Users/ken/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -framework Foundation /tmp/testcomp/testcomp/main.m | |
Interesting part of diagnostic output: | |
/tmp/testcomp/testcomp/main.m:57:13: remark: vectorized loop (vectorization factor: 16, unrolling interleave factor: 1) [-Rpass=loop-vectorize] | |
testBuffer[i] = (bytes[i] >= 128); | |
^ | |
output: | |
2014-12-03 11:33:33.070 a.out[48363:2396624] shortLen: 6 longLen:2493109 |
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
let é = "precomposed character!" | |
let é = "decomposed characters!" | |
println(é) // prints "precomposed character!" | |
println(é) // prints "decomposed characters!" |
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
func logWrap<Domain,Range>(f : Domain->Range) -> Domain->Range { | |
return { (args:Domain) -> Range in | |
println("called me!") | |
return f(args) | |
} | |
} | |
func foo(a:Int, b:Int)->Int { | |
return a + b | |
} |