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 will generate a number from 0.0 to 1.0, inclusive. | |
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); | |
//This will generate a number from 0.0 to some arbitrary float, X: | |
float r2 = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/X)); | |
//This will generate a number from some arbitrary LO to some arbitrary HI: | |
float r3 = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO); | |
// from http://stackoverflow.com/questions/686353/c-random-float-number-generation |
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
NSDictionary *jsonDictionary = @{@"username":@"[email protected]", @"password":@"aaaaa"}; | |
NSError *error; | |
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:0 error:&error]; | |
if (!jsonData) { | |
NSLog(@"JSON ERROR"); | |
} else { | |
NSString *JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding]; | |
NSLog(@"JSON OUTPUT: %@",JSONString); | |
} |
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 Eternal { | |
class func setObject(value: AnyObject!, forKey defaultName: String!) { | |
let defaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() | |
defaults.setObject(value, forKey:defaultName) | |
defaults.synchronize() | |
} | |
class func objectForKey(defaultName: String!) -> AnyObject! { | |
let defaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() |
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
#!flask/bin/python | |
from migrate.versioning import api | |
from flask import Flask | |
from flask.ext.sqlalchemy import SQLAlchemy | |
import os.path | |
basedir = os.path.abspath(os.path.dirname(__file__)) | |
app = Flask(__name__) | |
db = SQLAlchemy(app) |
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
override func preferredStatusBarStyle() -> UIStatusBarStyle { | |
return UIStatusBarStyle.LightContent | |
} |
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 | |
import SpriteKit | |
class PreloadData: NSObject { | |
var data = Dictionary<String, AnyObject>() | |
class var sharedInstance: PreloadData { | |
struct Static { | |
static let instance: PreloadData = PreloadData() | |
} |
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
//override | |
- (BOOL)touchesShouldCancelInContentView:(UIView *)view { | |
return ([view isKindOfClass:[UIButton class]]); | |
} | |
//init | |
self.selectedPhotosView.canCancelContentTouches = YES; |
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
Pod::Spec.new do |s| | |
s.name = "" | |
s.version = "0.1.0" | |
s.summary = "" | |
s.description = <<-DESC | |
DESC | |
s.homepage = "https://github.com/" | |
s.license = 'MIT' | |
s.author = { "" => "@gmail.com" } | |
s.source = { :git => "https://github.com/*.git", :commit => "a560b930fbd0439ec600fdd863db84eec21853cb", :tag => 'v0.1' } |
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
+ (BOOL) isValidEmail:(NSString *)s { | |
// An empty email is not ok | |
if (!s || [s length] <= 0) | |
return NO; | |
s = [s lowercaseString]; | |
// A huge email matching regular expression | |
NSString *emailRegEx = @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}" | |
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" |
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
+ (UIImage*)getScreenShot:(UIView*)view { | |
CGRect screenRect = [[UIScreen mainScreen] bounds]; | |
UIGraphicsBeginImageContext(screenRect.size); | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
[[UIColor blackColor] set]; | |
CGContextFillRect(ctx, screenRect); | |
[view.layer renderInContext:ctx]; | |
OlderNewer