Skip to content

Instantly share code, notes, and snippets.

@christophercotton
christophercotton / CGRectAspectFit.m
Created November 20, 2015 14:51 — forked from lanephillips/CGRectAspectFit.m
Objective-C code to fit a CGRect inside or outside another CGRect while maintaining aspect ratio. The fitted rectangle is centered on the target rectangle.
CGFloat ScaleToAspectFitRectInRect(CGRect rfit, CGRect rtarget)
{
// first try to match width
CGFloat s = CGRectGetWidth(rtarget) / CGRectGetWidth(rfit);
// if we scale the height to make the widths equal, does it still fit?
if (CGRectGetHeight(rfit) * s <= CGRectGetHeight(rtarget)) {
return s;
}
// no, match height instead
return CGRectGetHeight(rtarget) / CGRectGetHeight(rfit);
pod 'AFNetworking' # making requests
pod 'CocoaLumberjack' # logging
pod 'MagicalRecord' # coredata
pod 'FastttCamera' # taking pictures
pod 'WYPopoverController' # popover on iphone
pod 'FBSDKCoreKit' # facebook
pod 'FBSDKLoginKit' # facebook
pod 'FBSDKShareKit' # facebook
pod 'OAStackView' # UIStackView on iOS7
pod 'REMenu', :git => 'git@github.com:romaonthego/REMenu.git' # drop down menu
@christophercotton
christophercotton / DebugViews.swift
Created August 28, 2015 14:58
Debug versions of views which can be used to track down positioning issues
// DebugViews.swift
// Created by Christopher Cotton, no copyright
import UIKit
class DebugView: UIView {
override var bounds: CGRect {
didSet {
println("Bounds Changed: \(bounds)")
@christophercotton
christophercotton / UIView+Inspectable.swift
Created August 28, 2015 14:54
Adds inspectable properties to allow editing of the border and corner radius
// UIView+Inspectable.swift
//
// Created by Christopher Cotton. No Copyright
import UIKit
extension UIView {
@IBInspectable var borderColor:UIColor {
set {
@christophercotton
christophercotton / ViewController.swift
Created January 17, 2015 02:49
Display BLE Advertisement Data and when it changes
import UIKit
import CoreBluetooth
class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate {
var centralManager:CBCentralManager!
var queue:dispatch_queue_t!
var datas = [String : String]()
var peripherals = [CBPeripheral]()
override func viewDidLoad() {
@christophercotton
christophercotton / App icons.jstalk
Last active December 30, 2015 00:59 — forked from douglashill/App icons.jstalk
Modified the gist to allow it to work with the front most document.
function main(image, doc, layer) {
var sizes = [29, 40, 50, 57, 58, 72, 76, 80, 100, 114, 120, 144, 152, 1024];
for (var idx = 0; idx < sizes.length; idx++) {
doc.scaleImageToWidth(sizes[idx]);
doc.dataRepresentationOfType("public.png").writeToFile("/Users/cotton/Desktop/icon-" + sizes[idx] + ".png");
doc.undo();
}
}
@christophercotton
christophercotton / Article.rb
Created June 2, 2013 17:55
Article sample for PG Search
class Article < ActiveRecord::Base
attr_accessible :body, :title
end
class Article < ActiveRecord::Base
attr_accessible :body, :title
include PgSearch
end
@christophercotton
christophercotton / About.md
Created April 2, 2013 14:51
Apple GameKit Error 5003 during

I was getting the error:

Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo=0xb1935a0 {GKServerStatusCode=5003, NSUnderlyingError=0xb1866b0 "The operation couldn’t be completed. status = 5003, Found turn sequence at index: 1 that will never be reached because infinite timeout has specified for previous sequence", NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server.}

When trying to end the match with

  [match endTurnWithNextParticipants:nextParticipants turnTimeout:GKTurnTimeoutNone matchData:data completionHandler: ^(NSError *error) {
@christophercotton
christophercotton / OpaqueLayer.h
Created January 5, 2012 04:25
Basic Cocos2d Layer to swallow all the touch events on it
// Feel free to use. MIT License
#import <Foundation/Foundation.h>
#import "cocos2d.h"
// Layer that will just capture any touch events on it
@interface OpaqueLayer : CCLayerColor {
}
@christophercotton
christophercotton / PausableAdhwirlLayout.java
Created March 7, 2011 17:59
AdwhirlLayout that has a hack to pause the ad rotation
import android.app.Activity;
import com.adwhirl.AdWhirlLayout;
public class PausableAdhwirlLayout extends AdWhirlLayout {
public PausableAdhwirlLayout(final Activity context, final String keyAdWhirl) {
super(context, keyAdWhirl);
}
/**