Tuesday, January 22, 2013

College Courses

Well, I was placed in an advanced iOS development class, but even so the class wouldn't do me much good.  So I talked to the head of the Computer Science dept showing him some of my work, and now I get to help design some apps for the college and have it count as my class work.  Works for me. :)

How to batch vote on PollDaddy (Mac OS X) Hack

Well I decided to try to make a way to do batch votes on PollDaddy.  It was actually pretty easy once you play around with FireBug a little bit to find the necessary fields.  Kinda sloppy, but gets the job done.

Here is the source:
Updated 1/22/13 3:14p



//
//  main.m
//  Pollhacky
//
//  Created by Donald A Wittbrodt on 1/22/13.
//  Copyright (c) 2013 Donnie Wittbrodt. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DLoad.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        DLoad *dl = [[DLoad alloc] init];
        int numMillisecondsToDelay = 50;
        NSLog(@"Press 1 then Enter to exit.  Votes once every %d milliseconds to avoid invalid votes.", numMillisecondsToDelay);
        dl.delayTimeInMilliseconds = numMillisecondsToDelay;
        [NSThread detachNewThreadSelector:@selector(bruteVote) toTarget:dl withObject:nil];
        int i=0;
        while(1) {
            //Check to see if user cancelled
            scanf("%d", &i);
            if(i == 1) {
                //Tell the bruteVote to stop
                dl.stillVoting = NO;
                break;
            }
            //Give the main thread a small break to ease cpu usage
            usleep(0.5);
        }
        [dl release];
        
    }
    return 0;
}






//
//  DLoad.h
//  Pollhacky
//
//  Created by Donald A Wittbrodt on 1/22/13.
//  Copyright (c) 2013 Donnie Wittbrodt. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface DLoad : NSObject <NSURLConnectionDelegate>
{
    BOOL stillVoting;
    int delayTimeInMilliseconds;
    
    
}
-(void)bruteVote;
@property BOOL stillVoting;
@property int delayTimeInMilliseconds;
@end






//
//  DLoad.m
//  Pollhacky
//
//  Created by Donald A Wittbrodt on 1/22/13.
//  Copyright (c) 2013 Donnie Wittbrodt. All rights reserved.
//

#import "DLoad.h"

@implementation DLoad
@synthesize stillVoting, delayTimeInMilliseconds;

-(id)init
{
    self = [super init];
    if(self) {
        stillVoting = YES;
        delayTimeInMilliseconds = 250;
    }
    return self;
}

-(void)bruteVote
{
    while(stillVoting) {
        //Find the poll id for the poll you want
        NSString *pollID = @""; //Example: 6830128
        //Find the answer id for the answer you want
        NSString *answerID = @""; //Example: 31000396
        
        NSURL *pollURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://polldaddy.com/poll/%@/", pollID]];
        
        //Get the hmtl string to get the time and token fields
        NSString *getStr = [NSString stringWithContentsOfURL:pollURL encoding:NSUTF8StringEncoding error:nil];
        //Get the time
        NSString *t = [[[[getStr componentsSeparatedByString:@",&quot;t&quot;:"] objectAtIndex:1] componentsSeparatedByString:@",&quot;"] objectAtIndex:0];
        //Get the token
        NSString *token = [[[getStr componentsSeparatedByString:@"&quot;n&quot;:&quot;"] objectAtIndex:1] substringWithRange:NSMakeRange(0, 32)];
        
        NSString *fURLString = [NSString stringWithFormat:@"http://polldaddy.com/vote.php?va=10&pt=0&r=0&p=%@&a=%@%%2C&o=&t=%@&token=%@", pollID, answerID, t, token];
        NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:fURLString] encoding:NSUTF8StringEncoding error:nil];
        
        //NSLog(@"%@", str);
        if([str rangeOfString:@"Thank you for voting!"].location != NSNotFound) {
            NSLog(@"Voted!! :)");
        }
        else {
            NSLog(@"Vote failed. :(");
        }
        
        //Sleep delayTimeInMilliseconds to give cpu a break
        usleep(delayTimeInMilliseconds);
    }
}
@end