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
// Fischer-Yates shuffle | |
function shuffle(array) { | |
var m = array.length, t, i; | |
while (m) { | |
i = Math.floor(Math.random() * m--); | |
t = array[m]; | |
array[m] = array[i]; | |
array[i] = 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
/** | |
* An example CORS-compliant method. It will allow any GET, POST, or OPTIONS requests from any | |
* origin. | |
* | |
* In a production environment, you probably want to be more restrictive, but this gives you | |
* the general idea of what is involved. For the nitty-gritty low-down, read: | |
* | |
* - https://developer.mozilla.org/en/HTTP_access_control | |
* - http://www.w3.org/TR/cors/ | |
* |
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 a path to a directory, and make sure it exists. | |
// The iOS documentation will tell you that URLs are preferred, but there is no createDirectory method for | |
// URLs. So we have to use string paths instead. | |
// Create a sub-directory in the application's Documents directory. Return the path on success, or nil on failure. | |
- (void)createDocumentSubdirectory:(NSString*)dirName { | |
NSString *retval = nil; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *dirPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:dirName]; | |
NSFileManager *fm = [[NSFileManager alloc] init]; |