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/")

Currently rated 5.0 by 1 people

  • Currently 5/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.8 by 10 people

  • Currently 2.8/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

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

Convert NSString to NSData

by alex 26. November 2010 02:13

NSString* string= @"Some String";

NSData* data=[string dataUsingEncoding:NSUTF8StringEncoding];

Currently rated 3.5 by 11 people

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

Tags: ,

General

Get Executable File MD5 Signature

by alex 25. November 2010 02:48

#include <CommonCrypto/CommonDigest.h>

 

@implementation YourClass

 

-(NSString*)getExecutableFileMD5Signature{

NSBundle *bundle = [NSBundle mainBundle];

    NSDictionary *info = [bundle infoDictionary];

NSString *execName = [info objectForKey:@"CFBundleExecutable"];

NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.app/%@", NSHomeDirectory(), execName, execName]];

return [self cHash:@"md5" data:data];

}

 

-(NSString*)cHash:(NSString*)algo data:(NSData*)data{

NSData *rdata;

if ([algo isEqualToString:@"sha1"]) {

unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH];

CC_SHA1([data bytes], [data length], hashBytes);

rdata = [NSData dataWithBytes:hashBytes length:CC_SHA1_DIGEST_LENGTH];

}else if ([algo isEqualToString:@"md5" ]) {

unsigned char hashBytes[CC_MD5_DIGEST_LENGTH];

CC_MD5([data bytes], [data length], hashBytes);

rdata = [NSData dataWithBytes:hashBytes length:CC_MD5_DIGEST_LENGTH];

} else {

return @"NULL";

}

return [rdata stringWithHexBytes];

}

 

@end

 

 

//add new method to NSData Class

//convert NSData to HEX NSString

@implementation NSData (NSDataStrings)

 

- (NSString*)stringWithHexBytes {

static const char hexdigits[] = "0123456789abcdef";

const size_t numBytes = [self length];

const unsigned char* bytes = [self bytes];

char *strbuf = (char *)malloc(numBytes * 2 + 1);

char *hex = strbuf;

NSString *hexBytes = nil;

for (int i = 0; i<numBytes; ++i){

const unsigned char c = *bytes++;

*hex++ = hexdigits[(c >> 4) & 0xF];

*hex++ = hexdigits[(c ) & 0xF];

}

*hex = 0;

hexBytes = [NSString stringWithUTF8String:strbuf];

free(strbuf);

return hexBytes;

}

 

@end

Currently rated 4.0 by 4 people

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

Tags:

General

Get current language

by alex 18. October 2010 02:22

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSArray *languages = [defaults objectForKey:@"AppleLanguages"];

NSString *currentLanguage = [languages objectAtIndex:0];

 

NSLog(@"Current Locale: %@", [[NSLocale currentLocale] localeIdentifier]);

NSLog(@"Current language: %@", currentLanguage);


Currently rated 4.1 by 7 people

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

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen