Skip to content

Instantly share code, notes, and snippets.

View MosheBerman's full-sized avatar

Moshe MosheBerman

View GitHub Profile
@MosheBerman
MosheBerman / gist:3972164
Created October 29, 2012 07:38
Return a substring that fits a given rect
//
// NSString+MBDialogString.m
// TileParser
//
// Created by Moshe Berman on 9/23/12.
//
//
#import "NSString+MBDialogString.h"
@MosheBerman
MosheBerman / gist:3972372
Created October 29, 2012 08:31
Working text to dialog array
//
// Calculates the substring that fits in a frame
//
- (NSString *) substringThatFitsFrame:(CGRect)frame withFont:(UIFont *)font{
NSString *truncatedString = self;
CGSize clippingSize = CGSizeMake(frame.size.width, CGFLOAT_MAX);
@MosheBerman
MosheBerman / NSDate+TimeTravel.h
Created November 27, 2012 01:41
A header for an NSDate category.
#import <Foundation/Foundation.h>
@interface NSDate (timeTravel)
- (NSDate *) dateAdvancedByNumberOfDaysAgainstGregorianCalendar:(NSUInteger)numberOfDays;
- (NSDate *) dateRewoundByNumberOfDaysAgainstGregorianCalendar:(NSUInteger)numberOfDays;
- (NSDate *) dateAdvancedByNumberOfDays:(NSUInteger)numberOfDays againstCalendar:(NSCalendar *)calendar;
- (NSDate *) dateRewoundByNumberOfDays:(NSUInteger)numberOfDays againstCalendar:(NSCalendar *)calendar;
@MosheBerman
MosheBerman / Widget.cpp
Created December 3, 2012 01:59
Linked List
//
// Widget.cpp
// 3-LinkedLists
//
// Created by Moshe Berman on 12/2/12.
// Copyright (c) 2012 Moshe Berman. All rights reserved.
//
#include "Widget.h"
@MosheBerman
MosheBerman / Output 2
Created December 3, 2012 04:28
Output
Stocking 150 at $1 each.
Stocking 130 at $2 each.
(lldb) c
Process 6212 resuming
(lldb) p sales
(std::__1::vector<Sale, std::__1::allocator<Sale> > &) $0 = size=2: {
(Sale) [0] = {
(int) quantity = 0
(double) pricePerUnit = 0
}
@MosheBerman
MosheBerman / gist:5259848
Created March 28, 2013 01:52
display two spheres?
void display()
{
// Clear the previous frame
glClear(GL_COLOR_BUFFER_BIT);
{
glPushMatrix();
glTranslatef(0.5, 0.5, 0);
@MosheBerman
MosheBerman / gist:5366396
Created April 11, 2013 19:20
Animation transitions...
- (void) flipInWithCompletion:(MBTransitionCompletion)completion
{
BOOL displayingPrimary = [self isDisplayingPrimaryView];
UIView *frontView = [self frontView];
UIView *backView = [self backView];
UIView *wrapperView = [self wrapperView];
[wrapperView addSubview:frontView];
@MosheBerman
MosheBerman / gist:5385650
Created April 15, 2013 04:08
Calendar Touch handling
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if ([[self headerView] pointInside:point withEvent:event])
{
return YES;
}
else if([[self table] pointInside:point withEvent:event])
{
return YES;
@MosheBerman
MosheBerman / sum1.cpp
Created April 16, 2013 03:46
An example where we call a function called sum() from main();
// Prototypes:
int sum(int, int);
/* Main program */
int main()
{
int z = sum(1, 1); // z will become 2 here
@MosheBerman
MosheBerman / sum2
Created April 16, 2013 03:50
An example where we call a wrapper function from main.
/* Prototypes */
int sum(int, int);
void wrapper();
/* Main program */
int main()
{
wrapper();