Skip to content

Instantly share code, notes, and snippets.

View chrisbrandow's full-sized avatar

Chris Brandow chrisbrandow

View GitHub Profile
@chrisbrandow
chrisbrandow / recursive cellContainingView
Created October 4, 2014 05:46
a recursive method for identifying the UITableViewCell that contains a particular UIView or UIView subclass (i.e. UIControl) object in its view hierarchy.
- (UITableViewCell *)cellContainingView:(UIView *)view {
return (!view || [view isKindOfClass:[UITableViewCell class]]) ? (UITableViewCell *)view : [self cellContainingView:view.superview];
}
@chrisbrandow
chrisbrandow / polygonLayerMask
Created October 14, 2014 06:11
arbitrary polygon with arbitrary corner radius layer.mask
- (UIBezierPath *)pathForView:(UIView *)button withVertices:(CGFloat)vertices initialPointAngle:(CGFloat)initialAngle cornerRadius:(CGFloat)pCornerRadius lineWidth:(CGFloat)lineWidth{
CGFloat angle = 2*M_PI/vertices;
CGPoint buttonCenter = CGPointMake(button.frame.size.width/2, button.frame.size.height/2);
CGFloat totalRadius = button.frame.size.width/2;
CGFloat innerRadius = totalRadius - pCornerRadius -lineWidth;
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
@chrisbrandow
chrisbrandow / golden ratio buttons
Created October 22, 2014 20:56
This creates an array of evenly distributed buttons that are sized and spaced such that the spacing + buttonWidth = 1.618*buttonWidth
+ (NSArray *)evenlySpacedGoldenRatioButtonsWith:(NSInteger)numberOfButtons width:(CGFloat)spaceWidth yPos:(CGFloat)spaceHeight {
//this gives position in purely frame Math way
//an autolayout method should be made -- trying to think how I want to implement that -- method that takes view and buttons -- block?
CGFloat buttonWidth = spaceWidth/(1.303*(CGFloat)numberOfButtons + 0.3083);
CGFloat buttonSpacing = 0.3083*buttonWidth;
NSMutableArray *buttons = [NSMutableArray new];
for (NSInteger i = 0; i < numberOfButtons; i++) {
- (UIBezierPath *)pathForView:(UIView *)button withVertices:(CGFloat)vertices initialPointAngle:(CGFloat)initialAngle cornerRadius:(CGFloat)pCornerRadius lineWidth:(CGFloat)lineWidth{
    
    CGFloat angle = 2*M_PI/vertices;
    
    CGPoint buttonCenter = CGPointMake(button.frame.size.width/2, button.frame.size.height/2);
 
    CGFloat totalRadius = button.frame.size.width/2;
    CGFloat innerRadius = totalRadius - pCornerRadius -lineWidth;
    
@chrisbrandow
chrisbrandow / themedPlistToColorList
Last active August 29, 2015 14:24
command line tool to convert plist with hex color values to Os X color list
//
// main.m
// ColorListFromPList
//
// Created by Christopher Private on 7/12/15.
// Copyright (c) 2015 Flouu. All rights reserved.
//
@import AppKit;
@chrisbrandow
chrisbrandow / colorListToPlist
Created July 19, 2015 06:32
Command Line tool to turn .clr file into Theme plist
//
// main.m
// CreatePListFromColorLists
//
// Created by Christopher Private on 7/13/15.
// Copyright (c) 2015 Flouu. All rights reserved.
//
@import AppKit;
const NSString *hexStringForColor(NSColor *color);
@chrisbrandow
chrisbrandow / centered swiping collectionView
Created October 2, 2015 22:08
An implementation of twitter suggested app side-swiping
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
targetContentOffset->x = [self targetOffsetX:targetContentOffset->x inCollectionView:(UICollectionView *)scrollView velocity:velocity];
}
- (CGFloat)targetOffsetX:(CGFloat)offsetX inCollectionView:(UICollectionView *)collectionView velocity:(CGPoint)velocity {
if (![collectionView isKindOfClass:[UICollectionView class]]) {
return offsetX;
}
NSInteger index = [self indexForScrollView:collectionView targetOffsetX:offsetX velocity:velocity];
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
//Instead of:
func printAllKeys() {
var current: LLNode! = head
print("------------------")
while (current != nil) {
print("link item is: \(current.key)")
current = current.next
}
}
#!/usr/bin/swift
// Swift 3.0
//
// main.swift
// CSVToTables
//
// Created by Christopher Brandow on 7/12/16.
// Copyright © 2016 flouu. All rights reserved.
//
@chrisbrandow
chrisbrandow / Big O notation
Created November 2, 2016 18:21
results testing linear search vs. binary search
import Foundation
var array = [Int]()
for i in 1 ..< 10000000 {
array.append(i)
}
//let numberList = array
extension Array where Element: Comparable {