Skip to content

Instantly share code, notes, and snippets.

View josephquigley's full-sized avatar

Joseph Quigley josephquigley

View GitHub Profile
@josephquigley
josephquigley / jq-home-assistant-low-battery-blueprint-v1.yaml
Last active December 5, 2023 18:08
Home Assistant Low Battery Blueprint (v1)
blueprint:
name: Low battery level detection for all battery sensors
description:
Regularly test all sensors with 'battery' device-class for crossing
a certain battery level threshold and if so execute an action.
domain: automation
input:
threshold:
name: Battery warning level threshold
description:
@josephquigley
josephquigley / DynamicFetchRequestView.swift
Created October 21, 2020 15:32
Dynamic SwiftUI Fetch Request View
/*
The MIT License (MIT)
Copyright © 2020 Joseph Quigley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH TH
@josephquigley
josephquigley / QueryExample.swift
Created October 21, 2020 15:29
Example for Property Wrapper SwiftUI Dynamic Fetch Request
import SwiftUI
struct ExampleView: View {
@Query
private var inStockQuery: QueryController<InventoryItem>
@Environment(\.managedObjectContext)
private var viewContext
@State
@josephquigley
josephquigley / Query.swift
Created October 21, 2020 15:19
Property Wrapper SwiftUI Dynamic Fetch Request
/* The MIT License (MIT)
Copyright © 2020 Joseph Quigley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH TH
@josephquigley
josephquigley / SwiftUI TabBar With Icon Changes Upon Selection.swift
Last active October 29, 2019 21:05
SwiftUI TabView with icons that change upon selection. It's not immediately clear how to change the icon of a TabView in SwiftUI. But it is actually possible, with some gotchas.
//First pass with manual index tracking below. Keep scrolling for a safer, but harder to read example!
struct ContentView: View {
@State private var visualSelectedIndex = 0
@State private var programmaticSelectedIndex = 0
var body: some View {
// The selection binding allows for programmtically changing the tab
// However, changing the value from within `.onAppear` breaks things and seems to cause an infinite loop.
// This is why there are two indexes being tracked.
TabView(selection: $programmaticSelectedIndex) {
@josephquigley
josephquigley / MKMapView+ViewSpanDistance.swift
Created November 30, 2018 17:33
MKMapView Distance Of View Span
/*
Copyright 2018 Joseph Quigley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
@josephquigley
josephquigley / PopViewControllerButton.swift
Last active August 3, 2018 04:12
Highly abstracted, very configurable UIButton subclass that automatically dismisses modals or pops view controllers.
Copyright 2018 Joseph Quigley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OT
@josephquigley
josephquigley / RealmDBController.swift
Last active February 20, 2018 05:01
A handy wrapper For Realm for #DRY database interaction between view controllers, models and databases
/* Copyright 2018 Joseph Quigley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
@josephquigley
josephquigley / 3D Printer Asteroid Spawner Helpers.cs
Last active August 22, 2016 00:01
3D Printer Asteroid Spawner and "is inside" OBB point checker algorithms for Unity3d
void SpawnAsteroids() {
for (var i = 0; i<maxAsteroids; i++) {
//spawnArea is a Oriented Bounding Box with a face type that is a representation of
//the rectangle/plane of the face
var zPos = Vector3.Lerp(spawnArea.front.center(), spawnArea.back.center(), Random.Range(0f, 1f));
var xPos = Vector3.Lerp(spawnArea.left.center(), spawnArea.right.center(), Random.Range(0f, 1f));
var yPos = Vector3.Lerp(spawnArea.top.center(), spawnArea.bottom.center(), Random.Range(0f, 1f));
var pos = new Vector3(xPos.x, yPos.y, zPos.z);