Tuesday, November 19, 2013

Magic

Today I was complaining about reading an Android textbook.  Then as I realized it I realized that I was becoming more powerful.  I realized what I was reading was magic and that every page I read taught me how to do something, how to leverage technology in order to connect the world, how to shape the world in a way I see fit, in a way that move mankind forward.

I'm becoming more powerful with every page I read.  It's magic.  It allows me to do things other people can't and to touch the world globally.  I'm excited and empowered.

11/21/2013

I'm so excited by what I'm doing.  I'm almost done.  I'm almost completely done with this iPhone app.  I can see the end in sight and I'm really excited about it.

I've been working on it pretty hard and I can't wait until all is said and done.  I've got to work on the fax piece shortly but by and large it's almost finished.  Now I'm moving into some cooler parts like building the credit card processing back end and the fax piece.  I'm just moving at lightening speed and it feels really good to see the finish line in sight.  I'm starting to just work on bells and whistles but most of the stuff (I cringe to say) I've pretty much done before.  I have some pieces that still look like a little bit of a technical challenge but I think I can pretty safely say I'm pretty confident I can work my way through them at a reasonably rapid pace.  I think I can say I'm starting to just get nice.  

Not that much work left to do.  Then it's onto the website which I'm pretty confident I can just whip out.  I've got a lot of the code base pretty much done there.  Then I've got to order the graphics and just continue working.  Who knows?  Maybe by the end of the year I can have two websites up.  

I don't really care about the number of websites though.  What I do care about is that the site I have is really good and is really a real business.  Matter of fact I really don't want two sites.  I want one that works really well that has real traction that is moving along nicely.  I just want to continue what I'm doing and do it incredibly well.

Bad ass.  Bad ass.  Bad ass.  Bad ass.  Bad ass.  Did I mention really freaking cool?

All right.  I'm excited but I'd also better go to bed.  I'm almost tempted to build one view controller right now but that might be a bit of over kill.  Yup.  It's overkill.  Okay.  The News Hour and then bed.  

Tuesday, November 12, 2013

RTF::Writer Helpful Sites

http://search.cpan.org/perldoc?The_RTF_Cookbook

http://search.cpan.org/~sburke/RTF-Writer-1.11/lib/RTF/Writer.pod

Cool.

Monday, November 11, 2013

Easy Alert View Method

-(void) sendAlert:(NSString *)titleString setAlertMessage:(NSString*)messageString
{
    
    
    UIAlertView* alert = [[UIAlertView alloc]
                          initWithTitle:titleString
                          message:messageString
                          delegate:nil cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    
    [alert show];
    
    alert = nil;
    
    
    
    
}

Friday, November 8, 2013

Easy Methods to Retrieve RESTful Data in Objective-C

-(NSMutableArray*) getItemsArray:(NSDictionary *)itemsDictionary
{

   // FOR METHODS NOT NATIVE TO OBJECTIVE-C SEE MY METHODS AS I USE THEM HERE: 
   // IE, convertToString (etc.)
    NSString* numberOfItems = [itemsDictionary objectForKey: @"numberOfDetails"];
int intNumberOfItems = [numberOfItems intValue];
NSNumber* price, *quantity;
    NSString* stringData, *stringItemNumber;
    NSMutableArray *itemsArray;

    NSLog(@"OrdersViewController: getItemsArray: Number of Details: %@", numberOfItems);
    NSLog(@"OrdersViewController: getItemsArray: intNumberOfItems: %i", intNumberOfItems);
    
    indivItem *item;
    NSDictionary* indivItemDictionary;
    
    itemsArray = [[NSMutableArray alloc] init];

    
    for (int i = 0; i < intNumberOfItems; i++) {
        
item = [[indivItem alloc] init];
stringItemNumber = [NSString stringWithFormat:@"%i", i];
        
NSLog(@"Item Index Number: %@", stringItemNumber);
        
        indivItemDictionary = [itemsDictionary objectForKey:stringItemNumber];
        
        stringData = [indivItemDictionary objectForKey:@"price"];
        NSLog(@"String Data Price Data of an Item: %@", stringData);
price = [self convertStringToNumber:stringData];
        NSLog(@"Price Data of an Item: %@", [price stringValue]);
item.price = price;
NSLog(@"Item's Price: %f", [item.price floatValue]);
        
stringData = [indivItemDictionary objectForKey:@"quantity"];
quantity = [self convertStringToNumber:stringData];
        item.quantity = quantity;
NSLog(@"Quantity: %i", [item.quantity integerValue]);
stringData = [indivItemDictionary objectForKey:@"itemName"];
item.itemName = stringData;
NSLog(@"Item's Name: %@", item.itemName);
     
[itemsArray addObject:item];
        
        
}
    
    return itemsArray;

    
}

-(NSDictionary*)getOrderDictionary:(NSString*)customerID
{
    
    
    NSString *urlString = @"http://www.website.com/test/restfulScriptCall.pl?";
    NSString *queryString = @"";
    queryString = [queryString stringByAppendingString:@"parametername="];
    queryString = [queryString stringByAppendingString:parametervalue];
    
    // Step 5:  Make the RESTful call.
    
    urlString = [urlString stringByAppendingString:queryString];
    
    urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
    
    
    NSLog(@"OrdersViewController URL String: %@", urlString);
    
    NSURL *url = [NSURL URLWithString:urlString];
    NSData *dataURL = [NSData dataWithContentsOfURL:url];
    NSDictionary *myDict = [NSJSONSerialization JSONObjectWithData:dataURL options:0 error:nil];

    return myDict;
    
    
    

}

Objective-C Easy Conversion Methods

-(NSNumber*) convertStringToNumber:(NSString*)stringToConvert
{
    
    NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
    [f setNumberStyle:NSNumberFormatterDecimalStyle];
    NSNumber *myNumber = [f numberFromString:stringToConvert];
    
    return myNumber;
    
}


-(NSDate*) convertStringToDate:(NSString*)stringToConvert
{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    // this is imporant - we set our input date format to match our input string
    // if format doesn't match you'll get nil from your string, so be careful
    
    [dateFormatter setDateFormat:@"dd-MM-yyyy hh:mm:ss"];
    NSDate *dateFromString = [[NSDate alloc] init];
    
    // voila!
    
    dateFromString = [dateFormatter dateFromString:stringToConvert];
    
    return dateFromString;
    
}


-(NSString*) convertDateToString:(NSDate*)dateToConvert
{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    
    NSString *strDate = [dateFormatter stringFromDate:dateToConvert];
    
    return strDate;
    

}


-(NSString*) convertNumberToCurrencyString:(NSNumber*) numberValue
{
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    
    [formatter setMinimumFractionDigits:2];

    return [formatter stringFromNumber:numberValue];
    

}

Core Data Easy to Use Methods

// BEGINNING OF CORE DATA SECTION

-(void)printContext:(NSManagedObject *) managedObj
{
/*
     NSString *courierID, *emailAddress, *loggedIn, *timeLoggedIn;
     
     courierID = [NSString stringWithFormat:@"%@",[[managedObj valueForKey:@"courierID"]stringValue]];
     emailAddress = [managedObj valueForKey:@"emailAddress"];
     loggedIn = [[managedObj valueForKey:@"loggedIn"] stringValue];
     timeLoggedIn = [NSDateFormatter localizedStringFromDate:[managedObj valueForKey:@"timeLoggedIn"]
     dateStyle:NSDateFormatterShortStyle
     timeStyle:NSDateFormatterFullStyle];
     
     NSLog(@"GFMVC: Core Data Courier ID: %@", courierID);
     NSLog(@"GFMVC: Core Data Email Address: %@", emailAddress);
     NSLog(@"GFMVC: Core Data Logged In: %@", loggedIn);
     NSLog(@"GFMVC: Core Data Time Logged In: %@", timeLoggedIn);
     
     */
    return;
}


- (NSFetchedResultsController *)fetchedResultsController:(NSString *) entityName
{
    if (fetchedResultsController != nil) {
        return fetchedResultsController;
    }
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription
  entityForName:entityName inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];
    /*
     NSSortDescriptor *sort = [[NSSortDescriptor alloc]
     initWithKey:@"emailAddress" ascending:YES];
     [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
     
     [fetchRequest setFetchBatchSize:20];
     
     */
    
    NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:managedObjectContext sectionNameKeyPath:nil
  cacheName:@"Root"];
    
    
    fetchedResultsController = theFetchedResultsController;
    // self.fetchedResultsController.delegate = self;
    return fetchedResultsController;
}

-(void)saveContext:(NSManagedObjectContext *) managedObjContext
{
    
    if (managedObjContext == nil) {
        managedObjContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
        NSLog(@"After managedObjectContext: %@",   managedObjContext);
    }
    
    
    NSError *error = nil;
    
    if (![managedObjContext save:&error])
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
        
    }
    
}

-(void)setDataPoint:(NSManagedObject *) managedObj setManagedObjectContext: (NSManagedObjectContext* ) context setValue: (NSString*) valueString setKey:(NSString *) keyValue
{
    
    [managedObj setValue:valueString forKey:keyValue];
    
    [self saveContext:context];
    
    NSLog(@"D2D: OrdersViewController: Set Data Point %@: %@", keyValue, valueString);
    
    return;
}


-(NSString *)getDataPoint:(NSManagedObject *) managedObj setKey:(NSString *) keyString
{
    
    NSString *keyValue;
    
    if(managedObj != NULL)
    {
        keyValue = [managedObj valueForKey:keyString];
    }
    else
    {
        keyValue = @"";
    }
    
    NSLog(@"D2D: Core Data %@: %@", keyString, keyValue);
    
    return keyValue;
}


-(NSArray *)getArray:(NSManagedObjectContext *)context setEntityName:(NSString*) entityName
{
    
    
    NSEntityDescription *entityDesc = [NSEntityDescription entityForName:entityName
                                                  inManagedObjectContext:context];
    
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    
    [request setEntity:entityDesc];
    
    NSError *error = nil;
    
    NSArray *results = [context executeFetchRequest:request error:&error];
    
    return results;
    
}


-(NSManagedObject *) getManagedObject:(NSArray *) results setContext:(NSManagedObjectContext *) context
                        setEntityName:(NSString *)entityName
{
    
    NSManagedObject *newManagedObject = nil;
    
    if (results == nil)
    { // g
        
        newManagedObject = [NSEntityDescription
                            insertNewObjectForEntityForName:entityName
                            inManagedObjectContext:context];
        
        // set all the values for the object when I get home.
        
        
        NSLog(@"getManagedObject Point 1");
        
        
        
    }
    else if (results != nil && [results count] == 1) {
        
        newManagedObject = [results objectAtIndex:0];
        
        NSLog(@"getManagedObject Point 2");
        
    }
    else if (results != nil && [results count] == 0) {
        
        newManagedObject = [NSEntityDescription
                            insertNewObjectForEntityForName:entityName
                            inManagedObjectContext:context];
        
        NSLog(@"getManagedObject Point 3");
        
        
    } // g
    
    return newManagedObject;
    
}


-(NSManagedObjectContext *) getManagedObjectContext
{
    
    
    NSManagedObjectContext* context = [fetchedResultsController managedObjectContext];
    
    if (context == nil)
    { // f
        context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
        NSLog(@"After managedObjectContext: %@",   context);
    } // f
    
    return context;
    
    
}







// END OF CORE DATA SECTION