Skip to content

Instantly share code, notes, and snippets.

View adamnemecek's full-sized avatar

adamnemecek

View GitHub Profile
import Cocoa
enum CoroutineState {
case Fresh, Running, Blocked, Canceled, Done
}
struct CoroutineCancellation: ErrorType {}
class CoroutineImpl<InputType, YieldType> {
let body: (yield: YieldType throws -> InputType) throws -> Void
@adamnemecek
adamnemecek / copyable.swift
Created August 3, 2016 23:31
Copyable protocol (thanks to Mike Ash for help)
protocol Copyable: class {
init(copy: Self)
}
//
// this is a 'diffing' constructor, in your callback modify properties of $0 as needed
//
func _copy<T:Copyable, U>(obj: T, @noescape fun: inout T -> ()) -> U {
@adamnemecek
adamnemecek / coalesce.swift
Created June 29, 2016 15:59
Swift coalescing assignment operator
infix operator ??= {
associativity right
precedence 90
assignment
}
func ??=<T>(inout optional: T?, @autoclosure defaultValue: () -> T?) {
optional = optional ?? defaultValue()
}
import Foundation
func copy<T: AnyObject>(obj: T) -> T {
let ptr = UnsafeMutablePointer<T>.alloc(1)
ptr.initialize(obj)
return ptr.memory
}
class C: NonObjectiveCBase {
import Foundation
struct Test {
var value: Int = 0
var f: (Int, Int) -> Int {
mutating get {
var this = self
print("in getter value: \(this.value)")
% swiftc -Xllvm -help-hidden /tmp/foo.swift
USAGE: swift (LLVM option parsing) [options]
OPTIONS:
-a9-754319-workaround - Enable workarounds for A9 HW bugs #754319
-a9-754320-workaround - Enable workarounds for A9 HW bugs #754320
-aarch64-use-tbi - Assume that top byte of an address is ignored
-agg-antidep-debugdiv=<int> - Debug control for aggressive anti-dep breaker
-agg-antidep-debugmod=<int> - Debug control for aggressive anti-dep breaker
-aggressive-ext-opt - Aggressive extension optimization
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
ALWAYS_SEARCH_USER_PATHS = NO
ALWAYS_USE_SEPARATE_HEADERMAPS = YES
APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer
APPLE_INTERNAL_DIR = /AppleInternal
APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation
@adamnemecek
adamnemecek / .lldbinit
Last active August 29, 2015 14:25 — forked from zrxq/.lldbinit
comma script import ~/lldb/subl.py
comma script add -f subl.subl subl
@adamnemecek
adamnemecek / cocoa.snippets.mm
Last active August 29, 2015 14:19
cocoa.snippets.mm
#import <Foundation/Foundation.h>
void loadFScript() {
[[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] classNamed:@"FScriptMenuItem"] performSelector:@selector(insertInMainMenu)];
}
template<typename T>
inline
NSValue* NSValueFromStruct(T *object)
{
@adamnemecek
adamnemecek / nsvalue.mm
Created April 23, 2015 01:51
nsvalue.mm
#import <Foundation/Foundation.h>
template<typename T>
inline
NSValue* NSValueFromStruct(T *object)
{
return [NSValue value:object withObjCType:@encode(T)];
}
template<typename T>