Skip to content

Instantly share code, notes, and snippets.

@MaxGabriel
MaxGabriel / gist:1810765
Created February 12, 2012 20:39
drawRect Method for GraphView
//Draws a Cartesian Coordinate system and graphs an equation on it.
//Equation comes from GraphViewController (data source)
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGPoint midPoint; //center in coordinate system
midPoint.x = self.bounds.origin.x + self.bounds.size.width/2;
midPoint.y = self.bounds.origin.y + self.bounds.size.height/2;
@MaxGabriel
MaxGabriel / gist:1810885
Created February 12, 2012 21:15
CS 193p Graphing Calculator--Task 3: Seguing
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"graph"]) {
[segue.destinationViewController setGraphStack:[self.brain program]];
}
}
@MaxGabriel
MaxGabriel / gist:1811001
Created February 12, 2012 21:45
CS 193p Fall 2011 Assignment 3 Graphing Calculator--Task 3: Delegation
@class GraphView;
@protocol GraphViewDataSource
- (float)deltaY:(GraphView *)sender;
@end
@interface GraphView : UIView
@property (nonatomic) CGFloat xValue;
@property (nonatomic, weak) IBOutlet id <GraphViewDataSource> dataSource;
@MaxGabriel
MaxGabriel / gist:1811035
Created February 12, 2012 21:55
CS 193p Fall 2011 Assignment 3 Graphing Calculator--Task 3: Delegation2
@interface GraphViewController() <GraphViewDataSource>
@property (nonatomic, weak) IBOutlet GraphView *graphView;
@end
@MaxGabriel
MaxGabriel / gist:1811048
Created February 12, 2012 21:57
CS 193p Fall 2011 Assignment 3 Graphing Calculator--Task 3: Delegation3
- (float)deltaY:(GraphView *)sender
{
float xVar = sender.xValue;
id xVar2 = [NSNumber numberWithFloat:xVar];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:xVar2 forKey: @"x"];
float result = [CalculatorBrain runProgram:self.graphStack usingVariableValues:dict];
@MaxGabriel
MaxGabriel / gist:1847858
Created February 16, 2012 21:07
CS193p Fall 2011 Assignment 2--Calculator
//Iterates through program, an array of operations and NSNumbers
//Returns human-readable list of numbers and operations in RPN
+ (NSString *)descriptionOfProgram:(id)program
{
NSString *description = [[NSString alloc] init];
if ([program isKindOfClass:[NSArray class]]) {
for (int i=0; i<[program count]; i++) {
if ([[program objectAtIndex:i] isKindOfClass:[NSNumber class]]) {
@MaxGabriel
MaxGabriel / gist:1847902
Created February 16, 2012 21:14
CS193p Fall 2011 Assignment 2--Calculator Variables
+ (BOOL)isOperation:(NSString *)argument
{
NSSet *operations = [NSSet setWithObjects:@"+",@"-",@"/",@"*",@"sin",@"cos",@"sqrt",@"pi",nil];
if ([operations containsObject:argument])
return YES;
else
return NO;
}
//Converts variables in program to their double value
@MaxGabriel
MaxGabriel / gist:1926754
Created February 27, 2012 20:19
Set photo for UIScrollView
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = _photoName;
_imageView.image = _image;
_imageView.frame = (CGRect){CGPointZero, _imageView.image.size};
_scroller.contentSize = _imageView.image.size;
_scroller.minimumZoomScale = .3;
# ----------
# User Instructions:
#
# Define a function, search() that takes no input
# and returns a list
# in the form of [optimal path length, x, y]. For
# the grid shown below, your function should output
# [11, 4, 5].
#
# If there is no valid path from the start point
@MaxGabriel
MaxGabriel / gist:2084185
Created March 18, 2012 23:04
Udacity Unit 4-19 Code (written by Sebastian Thrun)
# ----------
# User Instructions:
#
# Implement the function optimum_policy2D() below.
#
# You are given a car in a grid with initial state
# init = [x-position, y-position, orientation]
# where x/y-position is its position in a given
# grid and orientation is 0-3 corresponding to 'up',
# 'left', 'down' or 'right'.