Skip to content

Instantly share code, notes, and snippets.

View gallaugher's full-sized avatar

Gallaugher gallaugher

View GitHub Profile
@gallaugher
gallaugher / Reviews.swift
Created June 21, 2018 22:01
Reviews.swift
import Foundation
import Firebase
class Reviews {
var reviewArray: [Review] = []
var db: Firestore!
init() {
db = Firestore.firestore()
}
@gallaugher
gallaugher / SpotReviewsTableViewCell.swift
Created June 21, 2018 22:19
SpotReviewsTableViewCell.swift
import UIKit
class SpotReviewsTableViewCell: UITableViewCell {
@IBOutlet weak var reviewTitleLabel: UILabel!
@IBOutlet weak var reviewTextLabel: UILabel!
@IBOutlet var starImageCollection: [UIImageView]!
var review: Review! {
didSet {
@gallaugher
gallaugher / SpotDetailViewController.swift's tableView(cellForRowAt:).swift
Created June 21, 2018 22:24
SpotDetailViewController.swift's tableView(cellForRowAt:)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewCell", for: indexPath) as! SpotReviewsTableViewCell
cell.review = reviews.reviewArray[indexPath.row]
return cell
}
@gallaugher
gallaugher / cameraOrLibraryAlert.swift
Created June 22, 2018 00:48
cameraOrLibraryAlert
func cameraOrLibraryAlert() {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let cameraAction = UIAlertAction(title: "Camera", style: .default) { _ in
self.accessCamera()
}
let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default) { _ in
self.accessLibrary()
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cameraAction)
@gallaugher
gallaugher / Photo.saveData().swift
Last active August 13, 2018 01:52
Photo.saveData()
func saveData(spot: Spot, completed: @escaping (Bool) -> ()) {
let db = Firestore.firestore()
let storage = Storage.storage()
// convert photo.image to a Data type so it can be saved by Firebase Storage
guard let photoData = self.image.jpegData(compressionQuality: 0.5) else {
print("*** ERROR: couuld not convert image to data format")
return completed(false)
}
let uploadMetadata = StorageMetadata()
uploadMetadata.contentType = "image/jpeg"
@gallaugher
gallaugher / Photos.loadData.swift
Last active June 22, 2018 20:16
Photos.swift's loadData method
func loadData(spot: Spot, completed: @escaping () -> ()) {
guard spot.documentID != "" else {
return
}
let storage = Storage.storage()
db.collection("spots").document(spot.documentID).collection("photos").addSnapshotListener { (querySnapshot, error) in
guard error == nil else {
print("*** ERROR: adding the snapshot listener \(error!.localizedDescription)")
return completed()
}
@gallaugher
gallaugher / Photo.swift's convenience init(dictionary).swift
Created June 22, 2018 18:39
Photo.swift's dictionary convenience initializer
convenience init(dictionary: [String: Any]) {
let description = dictionary["description"] as! String? ?? ""
let postedBy = dictionary["postedBy"] as! String? ?? ""
let date = dictionary["date"] as! Date? ?? Date()
self.init(image: UIImage(), description: description, postedBy: postedBy, date: date, documentUUID: "")
}
@gallaugher
gallaugher / ReviewTableViewController's updateUserInterface.swift
Created June 24, 2018 01:12
ReviewTableViewController's updateUserInterface function
func updateUserInterface() {
nameLabel.text = spot.name
addressLabel.text = spot.address
rating = review.rating
reviewTitleField.text = review.title
enableDisableSaveButton()
reviewTextView.text = review.text
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
reviewDateLabel.text = "posted: \(dateFormatter.string(from: review.date))"
@gallaugher
gallaugher / addBordersToEditableObjects.swift
Created June 24, 2018 01:14
ReviewTableViewController's addBordersToEditableObjects
func addBordersToEditableObjects() {
reviewTitleField.addBorder(width: 0.5, radius: 5.0, color: .black)
reviewTextView.addBorder(width: 0.5, radius: 5.0, color: .black)
buttonsBackgroundView.addBorder(width: 0.5, radius: 5.0, color: .black)
}
/*
RGBLedExample.ino
*/
#include <Easyuino.h> // Include the library in order to the compiler know you want Easyuino library
using Easyuino::RGBLed; // Necessary in order to use RGBLed
using Easyuino::Color; // Necessary for some method calls
int red_pin = 3; // Arduino pin connected to led red pin