Skip to content

Instantly share code, notes, and snippets.

View bluwave's full-sized avatar

Garrett Richards bluwave

View GitHub Profile
@bluwave
bluwave / MultiDirectionAdjudicatingScrollView.swift
Created July 16, 2017 05:30 — forked from andymatuschak/MultiDirectionAdjudicatingScrollView.swift
Source for the Khan Academy app's unusual scrolling interactions
//
// MultiDirectionAdjudicatingScrollView.swift
// Khan Academy
//
// Created by Andy Matuschak on 12/16/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
import UIKit.UIGestureRecognizerSubclass
@bluwave
bluwave / s3.sh
Created April 22, 2016 20:00 — forked from chrismdp/s3.sh
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
@bluwave
bluwave / CustomStringConvertibleProtocolExtension.swift
Last active April 21, 2016 21:25
Add default debug string method
extension CustomStringConvertible {
var description : String {
var description: String = ""
if self is AnyObject {
// may be able to use unsafeAddressOf now
description = "***** \(self.dynamicType) - <\(unsafeAddressOf((self as! AnyObject)))>***** \n"
} else {
description = "***** \(self.dynamicType) *****\n"
}
let selfMirror = Mirror(reflecting: self)
// only class types:
func myCast<MyClass: AnyObject>(value: AnyObject, type: MyClass.Type) -> MyClass? {
return value as? MyClass
}
// any type (class, struct, etc):
func myCast1<MyClass: Any>(value: Any, type: MyClass.Type) -> MyClass? {
return value as? MyClass
//
// MockURLProtocol.swift
// SolutoHome
//
// Created by Omer Levi Hevroni on 2/23/16.
// Copyright © 2016 Soluto. All rights reserved.
//
import Foundation
@bluwave
bluwave / rex.swift
Created February 22, 2016 17:07 — forked from erica/rex.swift
import Foundation
// Extend String to support regex searching by conforming
// to CustomStringConvertible
extension String: CustomStringConvertible {
public var description: String {return self}
}
// Regex support for keys
public extension Dictionary where Key: CustomStringConvertible {
@bluwave
bluwave / checkXcodeProjectLint.sh
Created January 29, 2016 20:08
plutil to check xcodeproject
plutil -lint MyProject.xcodeproj/project.pbxproj
import Foundation
extension Dictionary {
mutating public func setValue(val: AnyObject, forKeyPath keyPath: String) {
var keys = keyPath.componentsSeparatedByString(".")
guard let first = keys.first as? Key else { print("Unable to use string as key on type: \(Key.self)"); return }
keys.removeAtIndex(0)
if keys.isEmpty, let settable = val as? Value {
self[first] = settable
} else {
# must install gem
# sudo gem install cocoapods-deintegrate
pod deintegrate
@bluwave
bluwave / CGDrawGradientCircleBorder
Created May 1, 2015 20:29
Draw circle with a gradient color border, clear center
// Draw circle
CGContextSaveGState(context);
CGFloat lineWidth = 2.0f;
CGPoint center = CGPointMake(rect.size.width / 2, rect.size.height / 2);
UIBezierPath *outerCirclePath = [UIBezierPath bezierPath];
[outerCirclePath addArcWithCenter:center radius:(rect.size.height / 2) - insetPad/2 startAngle:0 endAngle:2 * M_PI clockwise:YES];
UIBezierPath *innerCirclePath = [UIBezierPath bezierPath];
[innerCirclePath addArcWithCenter:center radius:((rect.size.height / 2) - lineWidth - (insetPad/2)) startAngle:0 endAngle:2 * M_PI clockwise:YES];
[outerCirclePath appendPath:innerCirclePath];
outerCirclePath.usesEvenOddFillRule = YES;