Monday 30 March 2015

Py: Temperature info update speaker out after some time automatic in mac os x

Basically the concept is simple, we are going to write few lines of code in python to get temperature from some URL (openweathermap.org). Then make a string which should speak out by speaker.
Then finally make this python script into cron job into your Mac OS X.

Step 1: Write simple python script code

import urllib # Web service fetch
import json   # JSON parse 
import os     # text to speech convert

## get data from server
url = 'http://api.openweathermap.org/data/2.5/weather?q=Jaipur,In&units=metric'

u = urllib.urlopen(url)

## json parse 
data = json.load(u)


## make final string which should speak out
finalMessage = 'In '+data['name']+ ' temprature is '+ str(data['main']['temp']) + ' celcius. Forcasting says it is expacting '+data['weather'][0]['main']


### finally text to speak out
os.system("say "+ finalMessage)
#os.system("echo "+ finalMessage)

Step 2 : Check the program is working
python weather.py

Amazon EC2 Cloud setup (php+mysql)

Friday 27 March 2015

how can I check if a Gyroscope is present on iOS device?

- (BOOL) isGyroscopeAvailable
{
#ifdef __IPHONE_4_0
    CMMotionManager *motionManager = [[CMMotionManager alloc] init];
    BOOL gyroAvailable = motionManager.gyroAvailable;
    [motionManager release];
    return gyroAvailable;
#else
    return NO;
#endif

}

Get IP address of iOS Device though program

#include <ifaddrs.h>
#include <arpa/inet.h>

- (NSString *)getIPAddress {

    NSString *address = @"error";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    // retrieve the current interfaces - returns 0 on success
    success = getifaddrs(&interfaces);
    if (success == 0) {
        // Loop through linked list of interfaces
        temp_addr = interfaces;
        while(temp_addr != NULL) {
            if(temp_addr->ifa_addr->sa_family == AF_INET) {
                // Check if interface is en0 which is the wifi connection on the iPhone
                if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
                    // Get NSString from C String
                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];

                }

            }

            temp_addr = temp_addr->ifa_next;
        }
    }
    // Free memory
    freeifaddrs(interfaces);
    return address;

} 

Sunday 22 March 2015

Parallax effect in iOS

Parallax effect demo

what is Parallax effect?
read from here : http://en.wikipedia.org/wiki/Parallax But in term of programming, we can simply say varing speed/size of two different visible objects shows parallax effect. Now a days in web sites and mobile application it is most common attractive point.
So How to achieve this?
One point is that just varing speed or size of two visible object, shows parallax effect. So lets assume a situation where scrollview has a image at top and when scroll down it must zoom up to center, and when scroll up image must be vary with different speed (should be slow).

Monday 16 March 2015

Use iOS 8 default blur view

// -- add blur effect
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    
    [blurEffectView setFrame:self.view.bounds];
    
    
    [self.view addSubview:blurEffectView];

    //[self.view insertSubview:blurEffectView atIndex:0];

Thursday 12 March 2015

UIImagePickerController has iPad issue in iOS 8 : Attempt to present on which is already presenting (null)


I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController until the next iteration of the runloop, by doing this:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    // just add picker code here and it will work fine.
}];

Image Popup in popover view : small popup in UIView

- (IBAction)btnShowImage:(UIButton*)sender
{
//    Declare below declaration in .h file
//    UIPopoverController  *popoverVC;
    
    
    if([popoverVC isPopoverVisible])
    {
        //close the popover view if toolbar button was touched
        //again and popover is already visible
        //Thanks to @chrisonhismac
        
        [popoverVC dismissPopoverAnimated:YES];
        return;
    }
    
    //build our custom popover view
    UIViewController* popoverContent = [[UIViewController alloc] init];
    
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
    
    popoverView.backgroundColor = [UIColor whiteColor];
    
    popoverContent.view = popoverView;
    
    
    
    ////-- show image in popover view
    GPImageView *imgView = [[GPImageView alloc] initWithFrame:CGRectMake(10, 10, 230, 230)];
    
    NSString *imgURL = [SiteAPIURL stringByAppendingFormat:@"resizeImage.php?width=460&height=460&imagename=%@", dictCustomer[@"photo"]];
    
    [imgView setImageFromURL:imgURL
       showActivityIndicator:YES
               setCacheImage:YES];
    
    [popoverView addSubview:imgView];
    
    
    
    //create a popover controller
    popoverVC = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    
    popoverVC.contentViewController.preferredContentSize =  CGSizeMake(250, 250);
    
    [popoverVC presentPopoverFromRect:sender.frame   // did you forget to call this method?
                               inView:self.view
             permittedArrowDirections:UIPopoverArrowDirectionLeft
                             animated:YES];
}

Tuesday 3 March 2015

SNV terminal command MacOSX Subversion-Client-1.8.11_10.10.x

SVN
export PATH=/opt/subversion/bin:$PATH

//check out to pwd (.)
svn --username test --password 123 co https://192.168.1.40/svn/android

//push android/ to server
svn import -m "New Import"  android/ https://test@192.168.1.40/svn/android
--------------------------------------------------------------------------------------------

Make another build SDK (like iOS 6.1 add to XCode 5 where iOS7 sdk already available) in exsiting XCode SDK

Macintosh HD ▸ Applications ▸ Xcode5.app ▸ Contents ▸ Developer ▸ Platforms
STEP 1 : OPEN FINDER
STEP 2 : PRESS
CMD+SHIFT+g  
STEP 3 : PASTE BELOW LINE
/Applications/Xcode.app/Contents/Developer/Platforms
STEP 4: PASTE THE COPIED FIELES ON THAT FOLDER

Monday 2 March 2015

get all files in nested directory in iOS Objective C

NSArray *arrayFilesPath = [self openEachFileAt:DOCUMENT_PATH];
NSLog(@"All path %@", arrayFilesPath);
- (NSMutableArray*)openEachFileAt:(NSString*)path {
    NSString* file;
    
    NSMutableArray *arrayFilePath = [NSMutableArray new];
    
    NSDirectoryEnumerator* enumerator = [[NSFileManager defaultManager] enumeratorAtPath:path];
    
    while (file = [enumerator nextObject])
    {
        // check if it's a directory
        BOOL isDirectory = NO;
        
        [[NSFileManager defaultManager] fileExistsAtPath: [NSString stringWithFormat:@"%@/%@",path,file]
                                             isDirectory: &isDirectory];
        if (!isDirectory)
        {
            // open your file …
            [arrayFilePath addObject:[NSString stringWithFormat:@"%@/%@",path,file]];
        }
        else
        {
            [arrayFilePath addObjectsFromArray:[self openEachFileAt: file]];
        }
    }
    
    return arrayFilePath;
}

Sunday 1 March 2015

rename files in folder using python script

import os
# a~ipad.png to a.png
[os.rename(f, f.replace('~ipad', '')) for f in os.listdir('.') if not f.startswith('.')]