Skip to content

Instantly share code, notes, and snippets.

View aataraxiaa's full-sized avatar
:octocat:
Focusing

Pete Smith aataraxiaa

:octocat:
Focusing
  • DuckDuckGo
  • 07:46 (UTC +01:00)
View GitHub Profile
import SwiftUI
import MapKit
// Main view
struct ContentView: View {
// Provides an annotation immedidately (synchronously)
var synchronousAnnotationMaker = SynchronousAnnotationMaker()
var body: some View {
# Workflow to build and deploy site to Github Pages using Hugo
# Name of Workflow
name: github pages
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
@aataraxiaa
aataraxiaa / UIButton+Duplicate.swift
Created September 4, 2017 13:10
UIButton extension which enables the caller to duplicate a UIButton
//
// UIButton+Duplicate.swift
//
// Created by Peter Smith on 04/09/2017.
//
import UIKit
/// UIButton extension which enables the caller to duplicate a UIButton
extension UIButton {
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// ...
guard fetchedElements.last! != knownOldestElement else { return }
// Fetch next page
// ...
ref.queryOrderedByKey().queryEnding(atValue: "last_fetched_element_key").queryLimited(toLast: limit).observeSingleEvent(of: .value, with: { snapshot in
// Do stuff with this page of elements
//...
})
fileprivate let ref = FIRDatabase.database().reference().child("List_of_stuff")
_ = ref.queryLimited(toLast: 30).observe(.value, with: { snapshot in
// Do stuff here with the returned elements
//...
})
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.destination {
case let viewController1 as ViewController1:
self.viewController1 = viewController1
case let viewController2 as ViewController2:
self.viewController2 = viewController2
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Segue1" {
if let viewController1 = segue.destination as? ViewController1 {
self.viewController1 = viewController1
}
} else if segue.identifier == "Segue12" {
if let viewController2 = segue.destination as? ViewController2 {
self.viewController2 = viewController2
}
@aataraxiaa
aataraxiaa / ScalingCarouselView_CenterCell.swift
Created March 5, 2017 11:23
Method of calculating the centre cell in ScalingCarousel
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
var centerCell: UICollectionViewCell? = nil
// Get cell being displayed in the center of the screen
// Do this by getting the cell that is fully visible
for cell in scalingCarousel.visibleCells {
let cellRect = scalingCarousel.convert(cell.frame, to: nil)
// Get the cell that is fully visible, this will have an origin x value between 30 and 70
@aataraxiaa
aataraxiaa / UITextView+NewHeight.swift
Last active September 22, 2023 16:35
UITextView extension with method to calculate new height based on content
extension UITextView {
/**
Calculates if new textview height (based on content) is larger than a base height
- parameter baseHeight: The base or minimum height
- returns: The new height
*/
func newHeight(withBaseHeight baseHeight: CGFloat) -> CGFloat {