Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
kongtomorrow / gist:9a8530528cac708a7b48
Created December 3, 2014 01:06
Swift options for use with -Xllvm
% 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
@kongtomorrow
kongtomorrow / gist:8d1ac5161021451c794c
Last active April 21, 2023 17:14
you're freaking me out, Swift
func foo(f:()->(Int?)) {
println(f())
}
let bar : ()->Int = { 3 }
// foo shouldn't be able to take bar, should it?
foo(bar) // prints Optional(3)
// you're freaking me out, Swift. Did it allocate a wrapping closure?
@kongtomorrow
kongtomorrow / gist:e95bea13162ca0e29d4b
Last active August 31, 2022 16:20
Y combinator in Swift!
/* The Y combinator in Swift!
For a discussion of what the heck this is all about, see http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html
The nifty thing is that it allows us to implement recursion without the ability for a function to refer to itself from within its own definition.
Note how we manage a recursive definition of factorial without any function referring to its own name.
Thanks to @eridius for help with the SelfToUnderlying<T> type.
*/
@kongtomorrow
kongtomorrow / gist:974350
Created May 16, 2011 12:23
Get debug descriptions for enums in Objective-C via terrible terrible macro hackery.
/* Get strings descriptions for enum values for debugging.
Usage:
With enum
typedef enum {
AppleFruit = 0,
BlueberryFruit = 1,
BlackberryFruit = -1
} Fruit;
@kongtomorrow
kongtomorrow / gist:d36550fe7da2e84c8559
Created August 18, 2014 19:34
Swift seed 6: lexical scope nope?
func foo() {
func bar(x:Int)->String {
return "hello"
}
[1,2,3].map({bar($0)}) // "Cannot reference a local function from another local function"
}
JButton button;
Container contentPane = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
contentPane.setLayout(gridbag);
c.fill = GridBagConstraints.HORIZONTAL;
button = new JButton("Button 1");
c.weightx = 0.5;
c.gridx = 0;
@kongtomorrow
kongtomorrow / gist:6803313
Created October 3, 2013 01:37
compile-time generation of compile-time checked KVC key paths
#import <Foundation/Foundation.h>
#define KVCKeyPath_1(a) @"" a
#define KVCKeyPath_2(a, ...) a @"." KVCKeyPath_1(__VA_ARGS__)
#define KVCKeyPath_3(a, ...) a @"." KVCKeyPath_2(__VA_ARGS__)
#define KVCKeyPath_4(a, ...) a @"." KVCKeyPath_3(__VA_ARGS__)
#define KVCKeyPath_5(a, ...) a @"." KVCKeyPath_4(__VA_ARGS__)
#define KVCKeyPath_6(a, ...) a @"." KVCKeyPath_5(__VA_ARGS__)
#define KVCKeyPath_7(a, ...) a @"." KVCKeyPath_6(__VA_ARGS__)
[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: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: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 {
}