This file contains hidden or 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
| extension NSData{ | |
| func dataPacketsWithMaximumSize(size: Int) -> [NSData]{ | |
| if self.length <= size{ | |
| return [self] | |
| } | |
| var result: [NSData] = [] | |
| var index = 0 |
This file contains hidden or 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
| using UnityEngine; | |
| using System.Collections; | |
| using System.Linq; | |
| public class TapCharacterController : MonoBehaviour | |
| { | |
| public delegate void MotionEventHandler (GameObject sender); | |
| public delegate void TargetHandler (GameObject sender,GameObject target); |
This file contains hidden or 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
| //Taken from: http://stackoverflow.com/questions/15747777/delete-oldest-file-in-directory-ios | |
| +(void)removeOldestFileFromDir:(NSString *)path{ | |
| NSError *error = nil; | |
| NSFileManager *fm = [NSFileManager defaultManager]; | |
| NSArray *contents = [fm contentsOfDirectoryAtPath:path error:&error]; | |
| NSDate *oldest = [NSDate date]; | |
| NSString *oldestFileName = nil; | |
| for (NSString *f in contents) { | |
| NSString *filePath = [path stringByAppendingPathComponent:f]; |
This file contains hidden or 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
| //Taken from: http://stackoverflow.com/questions/2188469/calculate-the-size-of-a-folder | |
| - (unsigned long long int)folderSize:(NSString *)folderPath { | |
| NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil]; | |
| NSEnumerator *filesEnumerator = [filesArray objectEnumerator]; | |
| NSString *fileName; | |
| unsigned long long int fileSize = 0; | |
| while (fileName = [filesEnumerator nextObject]) { | |
| NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES]; |
This file contains hidden or 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 postfix operator unwraps an Optional, and if it is nil, returns the default value for that type. | |
| postfix operator *! {} | |
| postfix func *! (opt: String?) -> String{ | |
| return opt == nil ? "" : opt! | |
| } | |
| postfix func *! (opt: Int?) -> Int{ | |
| return opt == nil ? 0 : opt! |
This file contains hidden or 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
| //Taken from: http://stackoverflow.com/questions/12924094/simulate-a-picture-taken-screen-flash | |
| -(void)flashScreen{ | |
| // Flash the screen white and fade it out | |
| UIView *flashView = [[UIView alloc] initWithFrame:self.view.frame]; | |
| [flashView setBackgroundColor:[UIColor whiteColor]]; | |
| [[[self view] window] addSubview:flashView]; | |
| [UIView animateWithDuration:1.f | |
| animations:^{ |
This file contains hidden or 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 <CoreLocation/CoreLocation.h> | |
| #import <ImageIO/ImageIO.h> | |
| @interface CLLocation (EXIFGPS) | |
| - (NSDictionary*) EXIFMetadataWithHeading:(CLHeading*)heading; | |
| @end | |
| @interface NSDate (EXIFGPS) |
This file contains hidden or 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
| from math import radians, cos, sin, asin, sqrt | |
| #Taken from http://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points | |
| def haversine(lon1, lat1, lon2, lat2): | |
| """ | |
| Calculate the great circle distance between two points | |
| on the earth (specified in decimal degrees) | |
| """ | |
| # convert decimal degrees to radians |
This file contains hidden or 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 Handler(webapp2.RequestHandler): | |
| def get(self): | |
| x = SomeClass() | |
| #This... | |
| self.bind_request_attributes(x, attr_list=["attr1", "attr2", "attr3"]) | |
| #Is equal to this | |
| attr1 = self.request.get("attr1") | |
This file contains hidden or 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
| -(void)animateSquare:(SKSpriteNode *) node | |
| withIndex: (int)index | |
| andColor:(SKColor *) color | |
| rounds:(int)rounds | |
| duration: (NSTimeInterval) duration | |
| { | |
| CGSize newSize = [self sizeForSquareWithNumberOfRounds:rounds]; | |
| CGPoint center = CGPointMake(CGRectGetMidX(self.boardFrame) - newSize.width/2, |
NewerOlder