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 | |
let argumentCount = Int(C_ARGC) | |
var argumentArray: Array<String> = Array<String>() | |
for index in 0..argumentCount { | |
argumentArray.append(String.fromCString(C_ARGV[index])) | |
} |
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
public protocol MeasurementUnit { | |
// If we have one of this unit, how many millimeters is it? | |
class var asMillimeters: Double { get } | |
} | |
public class Inch : MeasurementUnit { | |
public class var asMillimeters: Double { | |
get { | |
return 25.4 | |
} | |
} |
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
// Create location url object | |
NSURL *url = [NSURL URLWithString:@"littlelocations://create?lat=18.99&lon=72.95&name=Mumbai%20Inner%20Circus"]; | |
// Test if Little Locations is installed | |
if([[UIApplication sharedApplication] canOpenURL:url] ) { | |
// Open Location in Little Locations | |
[[UIApplication sharedApplication] openURL:url]; |
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
// Here we'll use Swift's IDE-supporting reflect() | |
// function to build a basic JSON serializer. | |
// Per the fine engineers at WWDC, Swift's reflection support | |
// exists purely to support the IDE and the Playground. But | |
// we can have some fun with it anyway. ;) | |
class SerializerBase { | |
} |
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
// this is from the client code - simply pass the transactionReceipt property of the SKPaymentTransaction | |
// as the receipt parameter to the method below. This will POST the data to the mobile service which will, | |
// in turn, invoke the insert function on the server shown in this gist | |
- (void)insertReceipt:(NSData *)receipt completion:(CompletionBlock)completion | |
{ | |
NSString *string = [[NSString alloc] initWithData:receipt encoding:NSUTF8StringEncoding]; | |
[self.receipts insert:@{ @"receipt" : string } completion:^(NSDictionary *item, NSError *error) { | |
completion(); | |
}]; | |
} |
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
// Source: https://devforums.apple.com/message/866487#866487 | |
typedef int (*PYStdWriter)(void *, const char *, int); | |
static PYStdWriter _oldStdWrite; | |
int __pyStderrWrite(void *inFD, const char *buffer, int size) | |
{ | |
if ( strncmp(buffer, "AssertMacros: queueEntry", 24) == 0 ) { | |
return 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
import Foundation | |
// Executes an array of blocks in parallel, but only returns after they're all done. | |
func parallel(blocks: [() -> ()]) { | |
let group = dispatch_group_create() | |
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
for block in blocks { | |
dispatch_group_async(group, queue, block) | |
} |
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 | |
class StreamReader { | |
let encoding : UInt | |
let chunkSize : Int | |
var atEof : Bool = false | |
var fileHandle : NSFileHandle! | |
let buffer : NSMutableData! |
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 | |
extension Array { | |
/** | |
* Get first item in array. | |
* | |
* @return First item in array. | |
*/ | |
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
// For details, see http://mindsea.com/2012/12/18/downscaling-huge-alassets-without-fear-of-sigkill | |
#import <AssetsLibrary/AssetsLibrary.h> | |
#import <ImageIO/ImageIO.h> | |
// Helper methods for thumbnailForAsset:maxPixelSize: | |
static size_t getAssetBytesCallback(void *info, void *buffer, off_t position, size_t count) { | |
ALAssetRepresentation *rep = (__bridge id)info; | |
NSError *error = nil; |
OlderNewer