Skip to content

Instantly share code, notes, and snippets.

View slashingweapon's full-sized avatar

CJ Holmes slashingweapon

  • Sonoma County, CA
View GitHub Profile
@slashingweapon
slashingweapon / shuffle.js
Last active February 25, 2016 18:32
Javascript Bits
// 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;
}
@slashingweapon
slashingweapon / CORS.php
Last active October 2, 2015 07:38
Useful PHP Techniques
/**
* 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/
*
@slashingweapon
slashingweapon / createDocumentSubdir.m
Created July 4, 2011 17:39
Useful Objective-C Snippets
// 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];