Skip to content

Instantly share code, notes, and snippets.

@loganwright
loganwright / Timer.md
Created June 9, 2015 21:58
Timer struct for running very simple, and imprecise measuring of operations

#Timer

struct Timer : Printable {
    let start = NSDate()
    let name: String
    var description: String {
        let now = NSDate()
        let dif = now.timeIntervalSince1970 - start.timeIntervalSince1970
 let roundedDif = Double(round(1000 * dif)/1000)
@loganwright
loganwright / xcshortcuts.md
Created June 9, 2015 15:39
Xcode Shortcuts

##Useful Shortcuts

Here's a pretty decent reference as well: http://i.stack.imgur.com/Buohl.jpg

###Must Haves!

cmd + shift + o -- quick navigator -- works with classes, structs, functions, etc.

cmd + shift + j -- Show current file in navigator. Pairs well w/ quick navigator to see where the file fits into the full app.

@loganwright
loganwright / TimeOfDay.swift
Created June 2, 2015 14:20
A structure for holding and referencing the time of day
struct TimeOfDay {
// MARK: Public Properties
var hours: Int
var minutes: Int
var stringRepresentation: String {
var stringRepresentation = hours < 10 ? "0" : ""
stringRepresentation += "\(hours):\(minutes)"
@loganwright
loganwright / Picker.swift
Created June 2, 2015 02:54
Swift Generic UIPickerView
class PickerSource : NSObject, UIPickerViewDelegate, UIPickerViewDataSource {
var data: [[String]] = []
var selectionUpdated: ((component: Int, row: Int) -> Void)?
// MARK: UIPickerViewDataSource
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return data.count
}
@loganwright
loganwright / After.swift
Created May 21, 2015 18:01
Dispatching events to later in Swift.
func After(after: NSTimeInterval, op: () -> ()) {
After(after, op, nil)
}
func After(after: NSTimeInterval, op: () -> (), completion: (() -> Void)?) {
let seconds = Int64(after * Double(NSEC_PER_SEC))
var dispatchTime = dispatch_time(DISPATCH_TIME_NOW, seconds)
dispatch_after(dispatchTime, dispatch_get_main_queue()) {
let blockOp = NSBlockOperation(block: op)
blockOp.completionBlock = completion
@loganwright
loganwright / snippets.md
Created March 30, 2015 17:21
Command Line Snippet

Search a directory: http://stackoverflow.com/a/16957078/2611971

Do the following:

grep -rnw 'directory' -e "pattern"

-r is recursive, -n is line number and -w stands match the whole word. Along with these, --exclude or --include parameter could be used for efficient searching. Something like below:

grep --include=\*.{c,h} -rnw 'directory' -e "pattern"
@loganwright
loganwright / LGOutlinedTextLabel.h
Created March 28, 2015 17:55
Outlined Text Label
#import <UIKit/UIKit.h>
@interface LGOutlinedTextLabel : UILabel
@property (strong, nonatomic) UIColor *outlineColor;
@property (nonatomic) CGFloat outlineWidth;
@end
@loganwright
loganwright / Shell.swift
Last active November 12, 2016 10:46
Call shell commands from Swift
func shell(input: String) -> (output: String, exitCode: Int32) {
let arguments = split(input, maxSplit: Int.max, allowEmptySlices: true) {
$0 == " "
}
let task = NSTask()
task.launchPath = "/usr/bin/env"
task.arguments = arguments
task.environment = [
"LC_ALL" : "en_US.UTF-8",
@import UIKit;
CGFloat degreesToRadians(CGFloat degrees);
CGFloat distanceBetweenDegrees(CGFloat min, CGFloat max);
CGPoint pointOnArc(CGPoint center, CGFloat radius, CGFloat angleInDegrees);
@loganwright
loganwright / UIImage+Resize.h
Created February 19, 2015 20:57
UIImage+Resize
#import <UIKit/UIKit.h>
@interface UIImage (Resize)
- (UIImage *)scaleToSize:(CGSize)size;
@end