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
/* Get strings descriptions for enum values for debugging. | |
Usage: | |
With enum | |
typedef enum { | |
AppleFruit = 0, | |
BlueberryFruit = 1, | |
BlackberryFruit = -1 | |
} Fruit; |
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> | |
#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__) |
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
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; |
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 /tmp> clang -Wunused -c x.c | |
x.c:2:19: warning: unused variable 'x' [-Wunused-variable] | |
void f(void) {int x, y;} | |
^ | |
x.c:2:22: warning: unused variable 'y' [-Wunused-variable] | |
void f(void) {int x, y;} | |
^ | |
2 warnings generated. | |
ken@Nepheli /tmp> clang -Wunused -Werror -c x.c | |
x.c:2:19: error: unused variable 'x' [-Werror,-Wunused-variable] |
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 bricks : Array<UIView!> = { | |
var bricks = Array<UIView!>(count:brickCount, repeatedValue: nil) | |
for i in 0..brickCount { | |
let brick = UIView() | |
brick.backgroundColor = UIColor.blueColor() | |
brick.layer.borderColor = UIColor.greenColor().CGColor | |
brick.layer.borderWidth = 1.0 | |
bricks[i] = brick | |
} | |
return bricks |
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 myAnd(lhs : Bool, rhs : @auto_closure () -> Bool) -> Bool { | |
if lhs { | |
return rhs() | |
} else { | |
return false | |
} | |
} | |
func logAndBool(val : Bool) -> Bool { | |
println("evaluating and returning \(val)!") |
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 forAllCombinations<T>(r1 : Range<T>, r2 : Range<T>, body : (T, T) -> ()) { | |
for i in r1 { | |
for j in r2 { | |
body(i, j) | |
} | |
} | |
} | |
forAllCombinations(0..3, 0..5) { | |
(i, j) in |
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 takeThree(i : Int, j : Int, k : Int) { | |
println("yus") | |
} | |
let arg = (1,2,3) | |
takeThree(arg) |
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
#!/usr/bin/xcrun swift -i | |
func takeThree(i : Int, j : Int, k : Int) { | |
println("yus") | |
} | |
let arg = (1,2,3) | |
takeThree(arg) |
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
#!/usr/bin/xcrun swift -i | |
func ambiguous( f : Any...) { | |
for i in f { | |
println("\(i)") | |
} | |
} | |
let arg = (1,2) | |
ambiguous(arg) |
OlderNewer