Skip to content

Instantly share code, notes, and snippets.

View langford's full-sized avatar

Michael Langford langford

View GitHub Profile
@langford
langford / gist:c0d0cec92017b44fc72c
Created August 10, 2014 17:31
Instead of this in cellForRowAtIndexpath
In init:
-(instancetype)init{
...
_sections = @[
@[@"Twitter",@"Blog",@"Contact Us"],
@[@"nameone",@"nametwo",@"namethree"]
];
...
@langford
langford / gist:8284ed5ef5d3cfc9fa5c
Last active August 29, 2015 14:02
Naive Infix Array Combiner Operator for Swift
func + <T> (left: T[], right: T[]) -> T[] {
var newArray : T[] = []
for item in left {
newArray.append(item)
}
for item in right {
newArray.append(item)
}
return newArray;
}
@langford
langford / gist:c4d4a78673cdf8d660c3
Created June 5, 2014 01:50
Random test of method overloading
import UIKit
class Square {
var sideLength: Double
init(sideLength: Double, name: String) {
self.sideLength = sideLength
}
init(sideSlipperyness: Double, name: String) {
@langford
langford / gist:7e682d04f8f9ddead708
Last active August 29, 2015 14:02
Multiple methods with same type but different method param names. Still basically objective c style.
//
// ViewController.swift
// Silverton Resource Tracker
//
// Created by Michael Langford on 6/2/14.
// Copyright (c) 2014 Rowdy Labs LLC. All rights reserved.
//
import UIKit
let individualScores = [75, 43, 103, 87, 12]
var teamScore = 0
if 75 > 50 {
teamScore += 3 //this makes teamScore go from 0->3
} else {
teamScore += 1
}
@langford
langford / gist:0e26ed9d46246b9546fb
Last active August 29, 2015 14:02
My .clang-format that comes pretty close to Apple style using Tony Arnold's build of clang-format
BasedOnStyle: Chromium
AlignTrailingComments: true
BreakBeforeBraces: Stroustrup
ColumnLimit: 0
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
AllowShortIfStatementsOnASingleLine: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerBindsToType: false
@langford
langford / 0_reuse_code.js
Created April 3, 2014 14:31
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@implementation SwiperViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScreenEdgePanGestureRecognizer *edgePanLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleEdgePanLeft:)];
edgePanLeft.edges = UIRectEdgeLeft;
[self.view addGestureRecognizer:edgePanLeft];
@langford
langford / gist:9008754
Last active August 29, 2015 13:56
Cause IBOutletCollectionss are useful, but painful and ill supported by IB. You will want this code.
- (NSArray*)sortArrayByY:(NSArray*)array{
return [array sortedArrayUsingComparator:^NSComparisonResult(id label1, id label2) {
if ([label1 frame].origin.y < [label2 frame].origin.y) return NSOrderedAscending;
else if ([label1 frame].origin.y > [label2 frame].origin.y) return NSOrderedDescending;
else return NSOrderedSame;
}];
}
- (void)clearTextInArray:(NSArray*)array{
for (UILabel* label in array){
@langford
langford / Apple.style
Created January 2, 2014 17:54
This format file does 99% of what I want out of my code's formatting It's only big flaw is that it overindents blocks (which will need to be fixed by the tool writer). There is a workaround for for another bug as well in the spec. All and all, pretty good. strictcodeapp.com
! DO NOT CHANGE THIS FILE MANUALLY !
STYLE_NAME=Apple
S_NAME=array
S_BEG
name[SOME]
S_END