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 myClosure: (Int, Int) -> String |
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
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
addSquareToView(size: CGSizeMake(30, 30), color: UIColor.greenColor()); | |
} | |
func addSquareToView(size s: CGSize, color: UIColor) { | |
var square: UIView; | |
let frame = CGRectMake(10, 10, s.width, s.height); | |
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 InitProtocol { init() } | |
struct SomeStruct<T: InitProtocol> { | |
var x: T? = nil | |
mutating func instantiate() { | |
if x == nil { | |
x = T() | |
} | |
} | |
} |
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
// Text transformer (palindrome) | |
[self.textView transformSelectedTextWithTransformer:^NSAttributedString *(NSAttributedString *input) { | |
NSString *rawInput = [input string]; | |
NSMutableString *buffer = [NSMutableString string]; | |
unichar stackC; | |
for (NSInteger i=[rawInput length] - 1; i>=0; i--) { | |
stackC = [rawInput characterAtIndex:i]; | |
[buffer appendString:[NSString stringWithCharacters:&stackC length:1]]; | |
} | |
NSDictionary *attrs = [input attributesAtIndex:0 effectiveRange:NULL]; |
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
// Set up mentions plug-in | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
HKWMentionsChooserPositionMode mode = HKWMentionsChooserPositionModeEnclosedTop; | |
NSCharacterSet *controlCharacters = [NSCharacterSet characterSetWithCharactersInString:@"@+"]; | |
HKWMentionsPlugin *mentionsPlugin = [HKWMentionsPlugin mentionsPluginWithChooserMode:mode | |
controlCharacters:controlCharacters | |
searchLength:3]; | |
self.plugin = mentionsPlugin; | |
mentionsPlugin.delegate = [MentionsManager sharedInstance]; |
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 | |
// Build this as an OS X command line project, then run it. It should never terminate. | |
enum Value<T> { | |
case Nil | |
case Cons(T, LinkedList<T>) | |
} | |
final class LinkedList<T> { |
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 UIKit | |
// Running on Xcode 7.0 beta (7A121l) | |
// All running in a playground | |
// Open console (View -> Debug Area -> Show Debug Area) | |
// Define a non-generic free fn taking 1 arg | |
func notGeneric(x: String) { | |
print("notGeneric called") | |
} |
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
// Released under the terms of the MIT license. | |
struct PrefixedPostfixedSequence<T : SequenceType, U where U == T.Generator.Element> : SequenceType { | |
private let sequence : T | |
private let initial : U? | |
private let final : U? | |
init(_ sequence: T, initial: U? = nil, final: U? = nil) { | |
self.sequence = sequence | |
self.initial = initial |
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
#include <stdio.h> | |
struct n { | |
int v; | |
struct n* next; | |
}; | |
struct n* split_list(struct n* head, int pivot) { | |
struct n* cur = head; | |
struct n* lh = NULL; struct n* lt = NULL; |
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
// min_stack.c | |
// Austin Zheng | |
#include <stdio.h> | |
#include <stdlib.h> | |
struct min_stack { | |
int* v; // This array represents the main stack, and contains actual values. | |
int* m; // This array represents the min stack, and contains an index into the v array. | |
unsigned int v_ptr; // This is a pointer to the next free main stack slot. |
OlderNewer