Skip to content

Instantly share code, notes, and snippets.

View gallaugher's full-sized avatar

Gallaugher gallaugher

View GitHub Profile
@gallaugher
gallaugher / LBD6_Mini2.ino
Created June 10, 2018 00:25
Gallaugher Day 16, LBD 6, MiniProject 2
#define LED 6 // LED output pin = ~6
void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
@gallaugher
gallaugher / distance(from).swift
Created June 11, 2018 13:29
.distance(from:) to try in a playground
//: Playground - noun: a place where people can play
import UIKit
import CoreLocation
let lincolnMemorialLocation = CLLocation(latitude: 38.889553, longitude: -77.050176)
let capitolBuildingLocation = CLLocation(latitude: 38.890173, longitude: -77.009061)
let distance = lincolnMemorialLocation.distance(from: capitolBuildingLocation)
// distance will be calculated as 3567.82356314919 meters
@gallaugher
gallaugher / UIView+addBorder.swift
Created June 13, 2018 14:51
UIView+addBorder.swift
import Foundation
import UIKit
extension UIView {
func addBorder(width: CGFloat, radius: CGFloat, color: UIColor) {
self.layer.borderWidth = width
self.layer.borderColor = color.cgColor
self.layer.cornerRadius = radius
}
@gallaugher
gallaugher / Gallaugher LBD 7 Mini Project 1.ino
Created June 19, 2018 01:50
Gallaugher LBD 7 Mini Project 1 - Just the Red Light Working for Button Press
#define RED_PIN 3 // no need for equal. Don't use a semi-colon
#define BLUE_PIN 6
#define GREEN_PIN 5
#define RED_BUTTON 7
int buttonState = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
@gallaugher
gallaugher / Gallaugher LBD 7 Mini Project 1 - Red & Green Buttons Working.ino
Created June 19, 2018 02:23
Gallaugher LBD 7 Mini Project 1 - Red & Green Buttons
#define RED_PIN 3 // no need for equal. Don't use a semi-colon
#define BLUE_PIN 6
#define GREEN_PIN 5
#define RED_BUTTON 7
#define GREEN_BUTTON 8
int redButtonState = 0;
int greenButtonState = 0;
// the setup function runs once when you press reset or power the board
@gallaugher
gallaugher / Gallaugher LBD 7, Mini Project 1 - All Three Buttons Working.ino
Created June 19, 2018 02:24
Gallaugher LBD 7, Mini Project 1 - All Three Buttons Working
#define RED_PIN 3 // no need for equal. Don't use a semi-colon
#define BLUE_PIN 6
#define GREEN_PIN 5
#define RED_BUTTON 7
#define GREEN_BUTTON 8
#define BLUE_BUTTON 9
int redButtonState = 0;
int greenButtonState = 0;
int blueButtonState = 0;
#define RED_PIN 3 // no need for equal. Don't use a semi-colon
#define BLUE_PIN 6
#define GREEN_PIN 5
#define RED_BUTTON 7
#define GREEN_BUTTON 8
#define BLUE_BUTTON 9
int redButtonState = 0;
int greenButtonState = 0;
int blueButtonState = 0;
@gallaugher
gallaugher / ratingPropertyObserver.swift
Created June 20, 2018 17:45
rating property observer for Snacktacular
var rating = 0 {
didSet {
for starButton in starButtonCollection {
let image = UIImage(named: (starButton.tag < rating ? "star-filled": "star-empty"))
starButton.setImage(image, for: .normal)
}
review.rating = rating
}
}
@gallaugher
gallaugher / starButtonPressed.swift
Created June 20, 2018 18:08
9.12 code for @IBAction starButtonPressed
@IBAction func starButtonPressed(_ sender: UIButton) {
rating = sender.tag + 1 // add one since we're zero indexed
}
func saveData(spot: Spot, completed: @escaping (Bool) -> ()) {
let db = Firestore.firestore()
// Create the dictionary representing the data we want to save
let dataToSave = self.dictionary
// if we HAVE saved a record, we'll have a documentID
if self.documentID != "" {
let ref = db.collection("spots").document(spot.documentID).collection("reviews").document(self.documentID)
ref.setData(dataToSave) { (error) in
if let error = error {