Skip to content

Instantly share code, notes, and snippets.

View adamnemecek's full-sized avatar

adamnemecek

View GitHub Profile
% 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
import Foundation
struct Test {
var value: Int = 0
var f: (Int, Int) -> Int {
mutating get {
var this = self
print("in getter value: \(this.value)")
import Foundation
func copy<T: AnyObject>(obj: T) -> T {
let ptr = UnsafeMutablePointer<T>.alloc(1)
ptr.initialize(obj)
return ptr.memory
}
class C: NonObjectiveCBase {
@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()
}
@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 {
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
func responderForType<T>(from: UIResponder) -> T? {
var current = from
while let next = current.nextResponder() {
if let result = next as? T { return result }
current = next
}
return nil
}
@adamnemecek
adamnemecek / mcmc_exercices.py
Created August 31, 2016 20:45 — forked from mblondel/mcmc_exercices.py
MCMC exercises
"""
Exercises for the Markov Chain Monte-Carlo (MCMC) course available at
http://users.aims.ac.za/~ioana/
"""
import numpy as np
import numpy.linalg as la
import pylab
from scipy import stats
func encode<T>(var value: T) -> NSData {
return withUnsafePointer(&value) { p in
NSData(bytes: p, length: sizeofValue(value))
}
}
func decode<T>(data: NSData) -> T {
let pointer = UnsafeMutablePointer<T>.alloc(sizeof(T.Type))
data.getBytes(pointer)
enum Expr {
case Lit(Int)
indirect case Neg(Expr)
indirect case Add(Expr,Expr)
indirect case Mul(Expr,Expr)
indirect case Sub(Expr,Expr)
}
let spaces = many(oneof(" \n\r"))
func token<P: ParserType>(p: P) -> Parser<P.A> {