Skip to content

Instantly share code, notes, and snippets.

View lukewakeford's full-sized avatar
🚲
Cycling

Luke Wakeford lukewakeford

🚲
Cycling
View GitHub Profile
@lukewakeford
lukewakeford / Swift NSDate Extensions
Last active August 31, 2016 18:43
Swift NSDate Extensions
extension NSDate {
convenience init(ISO8601:String) {
let dateStringFormatter = NSDateFormatter()
dateStringFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
dateStringFormatter.locale = NSLocale.systemLocale()
let d = dateStringFormatter.dateFromString(ISO8601)
self.init(timeInterval:0, sinceDate:d!)
}
class func getLastDayOfMonthFrom(month:Int,year:Int) -> NSDate {
@lukewakeford
lukewakeford / Swift UIColor Extensions
Last active January 5, 2016 10:26
Swift UIColor Extensions
extension UIColor {
class func fromHexString(hex:String) -> UIColor {
let hex = hex.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet)
var int = UInt32()
NSScanner(string: hex).scanHexInt(&int)
let a, r, g, b: UInt32
switch hex.characters.count {
case 3: // RGB (12-bit)
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
case 6: // RGB (24-bit)
@lukewakeford
lukewakeford / Swift String Extensions
Last active January 5, 2016 10:26
Swift String Extensions
extension String {
func isEmail() -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluateWithObject(self)
}
func convertStringToDictionary() -> [String:AnyObject]? {
if let data = self.dataUsingEncoding(NSUTF8StringEncoding) {
do {
@lukewakeford
lukewakeford / Swift Todo Warnings Run Script
Last active August 29, 2015 14:15
Swift Todo Warnings Run Script
TAGS="TODO:|FIXME:"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
@lukewakeford
lukewakeford / UIView Borders
Created August 28, 2015 15:15
UIView Borders
extension UIView {
func roundCorners(corners:UIRectCorner, radius:CGFloat) {
let bounds = self.bounds;
let maskPath:UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius))
let maskLayer:CAShapeLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = maskPath.CGPath
@lukewakeford
lukewakeford / brap.rb
Last active November 2, 2016 09:39
Script for keeping an auto copying and deleting directory of gopro footage capped at 100gb.
require 'fileutils'
from = ARGV[0]
to = ARGV[1]
# Max source directory size set to 100gb
maxSourceSize = 107374182400
def directory_size(path)
path << '/' unless path.end_with?('/')
@lukewakeford
lukewakeford / gist:5e6872e39404bcbccdc4a78b70b276a8
Last active November 24, 2016 10:57
Toggle Hidden and Height Constraint
class ToggleHiddenLabel:UILabel {
var heightConstraint:NSLayoutConstraint!
var visible:Bool = false {
didSet {
if visible {
self.removeConstraint(self.heightConstraint)
self.hidden = false
} else {
self.addConstraint(self.heightConstraint)
@lukewakeford
lukewakeford / Tab Bar Example
Last active January 6, 2017 12:25
Tab Bar Example
class CustomTabbar:UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let data = [
1:"data",
2:"data",
3:"data",
4:"data"
@lukewakeford
lukewakeford / BackgroundLocation.swift
Created January 18, 2017 14:53
BackgroundLocation.swift
// BackgroundLocation.swift
import Foundation
class LocationManger : NSObject, CLLocationManagerDelegate {
static let sharedManager = LocationManger()
var locationManager:CLLocationManager!
var lastTimestamp:NSDate!
@lukewakeford
lukewakeford / google-swift-camera-360.swift
Created April 26, 2018 09:12
Google Maps Swift Camera Rotate 360 Smooth
var timer:Timer!
var degree = 0
@objc func rotate() {
// assumes google map called 'map'
self.map.animate(toBearing: CLLocationDirection(degree))
if degree == 360 {
timer.invalidate() // comment out this line for continual rotation
degree = 0
}
degree += 18