Skip to content

Instantly share code, notes, and snippets.

View lukewakeford's full-sized avatar
🚲
Cycling

Luke Wakeford lukewakeford

🚲
Cycling
View GitHub Profile
func sortConvex(input: [CLLocationCoordinate2D]) -> [CLLocationCoordinate2D] {
// X = longitude
// Y = latitudeß
// 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product.
// Returns a positive value, if OAB makes a counter-clockwise turn,
// negative for clockwise turn, and zero if the points are collinear.
func cross(P: CLLocationCoordinate2D, A: CLLocationCoordinate2D, B: CLLocationCoordinate2D) -> Double {
let part1 = (A.longitude - P.longitude) * (B.latitude - P.latitude)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.rankLabel.isHidden = true
if let rank = list.rank {
cell.rankLabel.setTitle(title: rank, titleFont: UIFont.customBold!, colour: .white)
cell.rankLabel.isHidden = false
}
}
@lukewakeford
lukewakeford / Reduce Playground Example
Last active January 8, 2019 14:29
Reduce Playground Example
import UIKit
struct product {
var price:Int?
var name:String
}
let array = [
product(price: 100, name: "First"),
product(price: nil, name: "Second"),
@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
@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 / 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 / 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 / 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 / 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 / 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/"