Monday, 22 August 2016

Install GitLab 5.3 on Mac OS X server 10.8.4

Below are the steps to install GitLab 5.3 on a fresh Mac OS X server 10.8.4 (server version 2.2)
1) Install a fresh mac ox x 10.8.4
2) Create user group “git” and a user “git” in this group
3) Enable remote login for “git” user
4) Install Xcode 4.6.2
5) Install command line tools in Xcode.
6) Install Home brew

Tuesday, 2 August 2016

ImagePicker in iOS 8+ (objective-c)

Here is the Rocket repo for the image picker and simple code for open actionsheet.
[[ImagePicker sharedPicker] imagePickerOnViewController:self
                                                   withSize:CGSizeMake(150, 150)
                                                   andImage:^(UIImage *img) {
                                                       if (img) {
                                                           self.imgView.image = img;
                                                       } else {
                                                           NSLog(@"Image not available");
                                                       }
                                                   }];



Wednesday, 15 June 2016

Creating HMAC in postman using CryptoJS

Place this script at pre-request-script and environment.secret is stored in environment variables or pass hardcoded here.
It will convert HMAC(.SHA256, /URI + /Body) and place into a global variable name as signature. which can pass on header like: x-pch-digest:{{signature}}

var index = request.url.indexOf('/');
var uri_path = request.url.substring(index);
var payload = uri_path + request.data;
console.log("Using payload as " + payload)
var hash = CryptoJS.HmacSHA256(payload, environment.secret);
var hashInBase64 = CryptoJS.enc.Hex.stringify(hash);
postman.setGlobalVariable("signature", hashInBase64);


Code signing using terminal

codesign --verify --force --sign "$CODE_SIGN_IDENTITY" "$CODESIGNING_FOLDER_PATH"
Walk through : http://stackoverflow.com/questions/20344255/secitemadd-and-secitemcopymatching-returns-error-code-34018-errsecmissingentit/22305193#22305193

Find UIViewController of the UIView in objective-c [Backtracking]

@interface UIView(UIViewControllerFinder)

- (UIViewController*)viewController;

@end


@implementation UIView(UIViewControllerFinder)

- (UIViewController*)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

@end

Try this code for find view-controller of view self.btnSubmit (UIButton) or any object inherits from UIView
UIViewController *vc = [self.btnSubmit viewController];

Sunday, 24 April 2016

Bulk task in one script using selenium (python) : Web automation


Hey I want create crash web hook for my 100 apps hosted on hockeyApp and I'm programmer so I cannot do it manually fill that form 100 times the same data for different apps, no public API provided by hockeyApp, so I wrote some python code using selenium tool for this task and voila, I feel I'm programmer.

Here is the codes 

iOS / iPhone Network ETag / HTTP 304 support

Your server team now enabled the ETag (server no change response HTTP 304) then how could you identify that this is going fine with your app, now NSURLConnection can do this, but not implicit. You need to do it by your way.
Nothing to worry just one line of code will do it.

NSMutableURLRequest *request = ...
request.cachePolicy = NSURLRequestReturnCacheDataElseLoad;

A very good article about NSURLCache.

Don't forget to increase the cache size by

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024
                                                       diskCapacity:20 * 1024 * 1024
                                                           diskPath:nil];
  [NSURLCache setSharedURLCache:URLCache];
}


iOS Network compression gzip

Most of the server enabled gzip compression on demand as header value contain Accept-Encoding:gzip. Now your boss ask that prove me that your app send this request as gzip, then you surf some  articles on internet that says NSURLConnection already send this header, don't need to send it externally. But your boss ask prove me that you got the compressed data, and you cannot find a way linear way to prove that, because NSURLConnection always decompress the data. 
Now you want to see that server send the compressed gzip data and NSURLConnection decompress for you. 

Then use below code for all explanations...



- (void)networkGzipTest {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.google.co.in"]];
    //    [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
    
    CFURLRequestRef requestRef = (__bridge CFURLRequestRef)[request performSelector:@selector(_CFURLRequest)];
    _CFURLRequestSetProtocolProperty(requestRef,kCFURLRequestDoNotDecodeData,kCFBooleanTrue);
    
    NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [urlConnection start];
}

Actually these two lines make you happy
CFURLRequestRef requestRef = (__bridge CFURLRequestRef)[request performSelector:@selector(_CFURLRequest)];
_CFURLRequestSetProtocolProperty(requestRef,kCFURLRequestDoNotDecodeData,kCFBooleanTrue);

Now you can print the size of your data without using above two line and with two lines. And all explanation you have now. [Read more]
Happy coding....Voila!

Disable ATS in iOS 9

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

192.168.1.2.xio.io for running ATS and request transfer host to 192.168.1.2. http://xip.io/

Python color terminal output

python terminal color print 
def prRed(prt): print("\033[91m {}\033[00m" .format(prt))
def prGreen(prt): print("\033[92m {}\033[00m" .format(prt))
def prYellow(prt): print("\033[93m {}\033[00m" .format(prt))
def prLightPurple(prt): print("\033[94m {}\033[00m" .format(prt))
def prPurple(prt): print("\033[95m {}\033[00m" .format(prt))
def prCyan(prt): print("\033[96m {}\033[00m" .format(prt))
def prLightGray(prt): print("\033[97m {}\033[00m" .format(prt))
def prBlack(prt): print("\033[98m {}\033[00m" .format(prt))

Add actual debug mode in iOS insist of DEBUG macro

You need to check that your app in debug mode or release mode and you edit the scheme, where DEBUG macro will defined by Xcode. But what happen if you change to release mode that time, it is hard to find that app build given by Xcode or archived. Also there is problem with preprocessor macro, if you are writing framework or dynamic lib for iOS, you cannot use preprocessors.

So find a scenario which mean that app is running by the Xcode build (debug) or archived (release), below method would help you. This method is popularly used by hockey app and most famous analytics. [Taken from Hockeyapp SDK]

#include <sys/sysctl.h>
- (BOOL)debug {
    static BOOL debuggerIsAttached = NO;
    static dispatch_once_t debuggerPredicate;
    dispatch_once(&debuggerPredicate, ^{
        struct kinfo_proc info;
        size_t info_size = sizeof(info);
        int name[4];
        
        name[0] = CTL_KERN;
        name[1] = KERN_PROC;
        name[2] = KERN_PROC_PID;
        name[3] = getpid();
        
        if (sysctl(name, 4, &info, &info_size, NULL, 0) == -1) {
            NSLog(@"App is running in debug mode");
            debuggerIsAttached = false;
        }
        
        if (!debuggerIsAttached && (info.kp_proc.p_flag & P_TRACED) != 0)
            debuggerIsAttached = true;
    });
    return debuggerIsAttached;
}

add .DS_Store to .gitignore

git ignore add .DS_Store
http://stackoverflow.com/questions/107701/how-can-i-remove-ds-store-files-from-a-git-repository
Remove existing files from the repository:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Add the line
.DS_Store
to the file .gitignore, which can be found at the top level of your repository (or created if it isn't there already). Then
git add .gitignore
git commit -m '.DS_Store banished!'

iOS / iPhone network packet tracker

It is hard to find that what packet request send by your iOS device. Most of apps doesn't use https, so the packets are in plane text, also most of the request doesn't use encryption over network so all packets are transmitted to plain text. So track the app network vulnerable, this may help you.
  1. Connect your iOS device by USB
  2. $ rvictl -s <UDID>
    where UDID is the UDID of your device (located in XCode under Devices, shortcut to with ⇧⌘2)
  3. $ sudo launchctl list com.apple.rpmuxd
  4. $ sudo tcpdump -n -t -i rvi0 -q -A tcp 

Tuesday, 10 November 2015

XCODE clean cmd

#!/bin/bash
rm -frd ~/Library/Developer/Xcode/DerivedData/*
rm -frd ~/Library/Caches/com.apple.dt.Xcode/*
echo done

Wednesday, 6 May 2015

OC: Swizzling: Category a class and override a method, not able to call super method, so Swizzling is the solution for you.

Hello Objective C, Apple iOS / Mac lovers,

Swizzling a technique may be useful for you in some scenario. Think a case If a super class method you want to override, but problem with that, That super class objects are already created in project. 
Now we have two ways: 
First: Traditional way, inherit that super class and override that method. But problem with this way is you have to manually change the new child class name from super class name. 
Class C1 has a method M1 which we want to override,
We made another class C2 : C1, and override method M1. 
In your project there are already many other classes have a object of C1. 
C1 *c11, *c12, *c13;
Now in find all class object which is Made of C1 and now replace to C2,
C2 *c11, *c12, *c13;
Don't you think it is too much of laborious work. Now consider the second way,

Second: Category concept in Objective C, Ok you can Category class C1 and override method M1. But Now there is another problem arises. You cannot call original method C1, because it is replaced by override method. It does mean, If you have 15 lines of code in M1 in C1, and Category CT1 override method M1, that 15 lines of codes is not available. So you have now two ways to solve:
A: You can rewrite those 25 lines of code in Category CT1 method M1. which is like again laborious work, less laborious but still you are a labour.
B: (RECOMMENDED Swizzling) Choose Swizzling technique to achieve that. In simple word, inheritance and category concept is now mix. In category if you will able to call super method then you don't have to write those 15 lines of code. This technique may be good for you if you are thinking of custom modification in lots of methods and you don't want to inherit because class name change is really pain. And you don't want to copy paste code of your super class overridden method. 
I think it is very approachable concept 

Wednesday, 22 April 2015

Py: Xcode: Add ARC disable flag to multiple files in Xcode project

I'm assume that Cocos2d files need to be ARC disables and each file is start with CC. Then If you have hundreds of files and you want to add ARC disable flag to each file, then my method could help you in quick way. Thanks for reading.
Beware Please take backup of your project before running this script.

Monday, 20 April 2015

Set UIImage by setting color name

#define UIColorFromRGBHex(rgbValue) \
  [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
                  green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
                   blue:((float)(rgbValue & 0xFF))/255.0 \
                  alpha:1.0]


#define UIColorFromRGB(nRed,nGreen,nBlue) \
  [UIColor colorWithRed:(nRed)/255.0 \
                  green:(nGreen)/255.0 \
                   blue:(nBlue)/255.0 \
                  alpha:1.0]

@interface UIImage (imageWithColor)

+ (UIImage *)imageWithColor:(UIColor *)color;

@end


@implementation UIImage (imageWithColor)

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end


[imageView setImage:[UIImage imageWithColor:UIColorFromRGB(255,0,0)]];

Thursday, 16 April 2015

What is Error *error, Error **error and &error?

Let us consider below code, here we are passing a NSString pointer to pointer object. Which is same as call by reference in C language. But in Objective C we are taking every Object as reference type so taking pointer of an pointer object we need to write it as NSString **, not like NSString *.

In simple word if you understand the below code as Call by reference and call by value concept in Objective C. You can easily find out that why most of the methods are defined as Error **error instead of Error *error. We all know that In C and Objective C method can return only single value as return type. So put value in Error we need a pointer of Error.
Therefore in Objective C we passing Error ** as &error. It is all syntactical thing related to Objective C. Concept is the same as C language calling by reference and value.
Voila for reading this

-(void)changePointerOfString:(NSString **)strVal {
        *strVal = @"New Value";
}

-(void)changeOfString:(NSString *)strVal {
        strVal = @"New Value";
}


-(void)caller {
        NSString *myStr = @"Old Value";
        // myStr has value 'Old Value'
        NSLog(@"%@", myStr);

       [self changeOfString:myStr];
       // myStr has value 'Old Value'
       NSLog(@"%@", myStr);
       
       [self changePointerOfString:&myStr];
       // myStr has value 'New Value'
       NSLog(@"%@", myStr);
}

Sunday, 12 April 2015

Ultra sonic distance test on raspberry pi

Our Motive to test ultra sonic waves, when object detect blink a led to show. Print the distance of object.  I have added a LED to show up the power is ON, one LED is check for pulse checking, and last LED will blink when object will detect. Object detection distance is set to 75 cm (.75m).