Skip to content

Instantly share code, notes, and snippets.

View sag333ar's full-sized avatar

sagar kothari sag333ar

View GitHub Profile
// ------------------------------------------------------------------------
// newSessionConfig.h
#import <Foundation/Foundation.h>
@interface SessionConfiguration : NSObject
@end
#import <Foundation/Foundation.h>
@interface SessionDelegate : NSObject <NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate>
+ (void)invokeAPIRequest:(NSMutableURLRequest*)request completionHandler:(void (^)(NSData* data, NSError *error))completionHandler;
@end
#import "SessionDelegate.h"
#import "SessionConfiguration.h"
@interface SessionConfiguration ()
+ (NSURLSessionConfiguration*)sessionConfig;
@end
@interface SessionDelegate ()
+ (SessionDelegate*)sharedSessionDelegate;
@property (nonatomic, strong) NSMutableDictionary *dForData;
#import <Foundation/Foundation.h>
#import "_01_API_Authenticate.h"
#import "_02_API_Register.h"
#import "_03_API_RegisterSocial.h"
#import "_04_API_ForgotPassword.h"
#define kAPI_Request_email @"email"
#define kAPI_Request_mobile @"mobile"
#define kAPI_Request_password @"password"
#define kAPI_Request_user_id @"user_id"
#import "API_Request.h"
#import "SessionDelegate.h"
NSMutableURLRequest * generateRequest(NSURL *URL, NSString *postString) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMethod:@"POST"];
NSData *postData = [postString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
@sag333ar
sag333ar / JSONUnixDate.m
Created April 16, 2014 08:46
Convert UnixTimeStamp Date with specified Timezone. Example "/Date(1395486890000+0530)/" as a sample value.
// Convert UnixTimeStamp Date with specified Timezone. Example "/Date(1395486890000+0530)/" as a sample value.
+ (NSDate *)DateFromJSONString:(NSString *)string {
static NSRegularExpression *dateRegEx = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dateRegEx = [[NSRegularExpression alloc] initWithPattern:@"^\\/date\\((-?\\d++)(?:([+-])(\\d{2})(\\d{2}))?\\)\\/$" options:NSRegularExpressionCaseInsensitive error:nil];
});
NSTextCheckingResult *regexResult = [dateRegEx firstMatchInString:string options:0 range:NSMakeRange(0, [string length])];
if (regexResult) {
@sag333ar
sag333ar / changeSearchBarKeyBoardAppearance.m
Created July 21, 2014 11:35
Change appearance of UISearchBar Keyboard.
+ (void)changeSearchBarColor:(UISearchBar *)searchBar {
for (UIView *subview in searchBar.subviews) {
for (UIView *subSubview in subview.subviews) {
if ([subSubview conformsToProtocol:@protocol(UITextInputTraits)]) {
UITextField *textField = (UITextField *)subSubview;
[textField setKeyboardAppearance: UIKeyboardAppearanceAlert];
break;
}
}
}
@sag333ar
sag333ar / GameScene
Created September 4, 2014 13:42
Default/File-template for Game-Scene in Cocos2d-x
//------------------------------------Headr File------------------------------------------
//----------------------------------------------------------------------------------------
#ifndef __GAME_SCENE_H__
#define __GAME_SCENE_H__
#include "cocos2d.h"
class GameScene : public cocos2d::LayerColor
{
public:
@sag333ar
sag333ar / SoundManagement
Last active August 29, 2015 14:06
Load, play, pause, stop - sound-effects & background music in Cocos2d-x & also set the volume for both
// load sound effect
CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("audio/menu-click.caf");
// load background sound
CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("audio/landing.mp3");
// play backgorund sound
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("audio/landing.mp3");
// play sound effect
@sag333ar
sag333ar / CreateLabel
Created September 4, 2014 13:56
Create label in Cocos2d-x & set few properties
// create label with text, font and font size
auto label = LabelTTF::create("Wheel of Fortune", "Marker Felt", 20);
// get the size of the label
Size labelSize = label->getDimensions();
// set the position of the label
label->setPosition(Vec2(20,20));
// set the text color of the label