Find switch operators in files

by alex 2. January 2012 09:04

import os

import sys

 

def processFile(fileName):

    f = open(fileName)

 

    switchFound = False

    foundOneBracket = False

    openBrackets = 0

    switchLineCount = 0

    lineCounter = 1

    switchStartedAt = 0

    printedFileName = False

 

    for line in f.readlines():

 

            if line.find("switch") > 0:

                switchLineCount = 0

                switchFound = True

                foundOneBracket = False

                switchStartedAt = lineCounter

 

            # now we need to count brackets

            if switchFound :

                if line.find("{") > 0:

                    openBrackets += 1

                    foundOneBracket = True

 

                if line.find("}") > 0 :

                    openBrackets -= 1

 

            switchLineCount += 1

 

            if switchFound and foundOneBracket and openBrackets == 0:

                if not printedFileName :

                    print fileName + ":"

                    printedFileName = True

 

                switchFound = False

                print  "switch: %d size %d" % (switchStartedAt, switchLineCount)

 

            lineCounter += 1

 

    pass

 

def processFolder(folderName):

    for root, dirs, files in os.walk(folderName):

        for name in files:

            filename = os.path.join(root, name)

            if filename.find(".svn") == -1 and filename[-2:] in ( ".m") :

                processFile(filename)

    pass

 

processFolder("/Users/alex/test/IPHTWO/")

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Handle taps within a UIWebView

by alex 2. January 2012 08:57

//1. Add UIGestureRecognizerDelegate to your interface:

 

@interface DocumentViewControler : UIViewController <UIGestureRecognizerDelegate>

 

//2. Add to viewDidLoad

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    UITapGestureRecognizer* singleTap=[[UITapGestureRecognizer

                                        alloc]initWithTarget:self action:@selector(handleSingleTap:)];

    singleTap.numberOfTouchesRequired=1;

    singleTap.delegate=self;

    [self.webView addGestureRecognizer:singleTap];

    [singleTap release];

}

 

//3. Add:

 

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer

                                                    *)otherGestureRecognizer {

    return YES;

}

 

//4.

 

-(void) handleSingleTap:(UITapGestureRecognizer *)recognizer  {

    NSLog(@"handleSingleTap");

    

    // Your code here

}

@end

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Check if file exists

by alex 4. July 2011 18:46

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagePath];

Currently rated 2.7 by 9 people

  • Currently 2.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

General | General | General | General

Show UIActionSheet

by alex 14. March 2011 01:45

 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

//SMS

if(buttonIndex == 0){


}

//EMAIL

if (buttonIndex == 1){

 

 

}

else

{

}

}

 

-(IBAction)emailAction{

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Send by" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"SMS", @"Email",nil];

actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

[actionSheet showInView:self.view];

[actionSheet release];

}


Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

UIAlertView without Buttons

by alex 12. March 2011 08:17

//Declare in class following vairiable

UIAlertView *alert;

 

-(void)showAlert{

    alert = [[[UIAlertView alloc] initWithTitle:@"Please Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];

    

    [alert show];

 

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

 

    indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);

    [indicator startAnimating];

    [alert addSubview:indicator];

    [indicator release];

}

 

-(void)dismissAlert{

    [alert dismissWithClickedButtonIndex:0 animated:YES];

    [alert release];

}


Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Send SMS

by alex 11. March 2011 00:09

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

switch (result) {

case MessageComposeResultCancelled:

NSLog(@"Cancelled");

break;

case MessageComposeResultFailed:{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Application" message:@"Unknown Error"

  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

[alert show];

[alert release];

break;}

case MessageComposeResultSent:

break;

default:

break;

}

[self dismissModalViewControllerAnimated:YES];

}

 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

//SMS

if(buttonIndex == 0){

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];

if([MFMessageComposeViewController canSendText])

{

controller.body = @"SMS Body";

controller.messageComposeDelegate = self;

controller.delegate = self;

[self presentModalViewController:controller animated:YES];

} else {

}

}

}

Currently rated 3.5 by 4 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Surviving BlackBerry

by alex 9. March 2011 21:48

Hello,

Recently I was asked to port application from iPhone/Android to Blackberry.

 Check out my separate blog about this "adventure" 

Thanks,

Alexander 

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Get current app version number from AndroidManifest.xml

by alex 20. February 2011 05:26

  //Usage from activity:

  //String verison = GlobalSettings.getVersionName(this,MyActivity.class)

  public static String getVersionName(Context context, Class cls) {

    try {

      ComponentName comp = new ComponentName(context, cls);

      PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);

      return "Version: " + pinfo.versionName;

    } catch (android.content.pm.PackageManager.NameNotFoundException e) {

      return null;

    }

  }


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Get current app version number from bundle

by alex 6. December 2010 00:02

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Check if we are running iOS 4+

by alex 1. December 2010 23:27

+(BOOL)isOS4{

NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"4.0" options: NSNumericSearch];

if (order == NSOrderedSame || order == NSOrderedDescending) {

return YES;

} else {

return NO;

}

}


 

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen