Skip to content

Instantly share code, notes, and snippets.

View samalone's full-sized avatar

Stuart A. Malone samalone

View GitHub Profile
@samalone
samalone / EnvironmentBinding.swift
Created October 23, 2023 18:01
Getting a SwiftUI Binding to an Environment object property
import SwiftUI
@Observable class Account {
var name: String = "Foo"
}
// What is the right way to get a Binding to a property of an Environment object?
struct AccountEditor: View {
@Environment(Account.self) var account
@samalone
samalone / transcript2.txt
Created August 10, 2023 16:30
Meeting transcript
machine and then add the last few cells with selected cells.
That's how I kind of think to do, maybe do something with maybe two or three antibodies with that scenario.
That way it's like a type and screen on a patient.
They get your screen results from the analyzer.
Then they get their panel result from the analyzer 'cause that's pretty typical.
@samalone
samalone / KeyboardMonitor.swift
Last active May 11, 2023 11:20
How to monitor the keyboard modifier flags from SwiftUI
import SwiftUI
@MainActor
class KeyboardMonitor: ObservableObject {
@Published var modifierFlags: NSEvent.ModifierFlags = NSEvent.modifierFlags
private var monitor: Any? = nil
private init() {
monitor = NSEvent.addLocalMonitorForEvents(matching: [.flagsChanged]) { event in
self.modifierFlags = event.modifierFlags
@samalone
samalone / MatrixOutline.swift
Last active May 1, 2023 18:14
Quick snippet for David
struct MatrixItem: Codable, Identifiable, Hashable {
var id: UUID = UUID()
let name: String
let rooms: [MatrixItem]?
}
struct ContentView: View {
@State private var demoState: [MatrixItem] = []
var body: some View {
@samalone
samalone / Archive inbox.scpt
Last active December 8, 2023 23:00
AppleScript to archive inbox emails older than 14 days to monthly folders
tell application "Mail"
set theCutoff to (current date) - (14 * days)
with timeout of 6000 seconds
set theMessages to every message of inbox where (date sent < theCutoff)
end timeout
repeat with theMessage in theMessages
try
set theMessage to contents of theMessage
set theDate to date sent of theMessage
set theBoxName to "Inbox/Inbox " & (year of theDate) & "-"
@samalone
samalone / Setup-development-environment.ps1
Last active January 21, 2020 17:14
PowerShell script to set up Windows 10 for Antigen Plus development
# Based on https://edi.wang/post/2018/12/21/automate-windows-10-developer-machine-setup
# and https://github.com/EdiWang/EnvSetup/
Set-ExecutionPolicy RemoteSigned
function Check-Command($cmdname) {
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
Write-Host ""
@samalone
samalone / Database+transaction.swift
Last active September 6, 2019 21:25
Transactions for Vapor 4 alpha 3
import FluentPostgresDriver
import FluentSQLiteDriver
// This extension adds transaction support to the Database protocol.
// It has to be specialized for each Database type used by your application,
// since the Database protocol does not support the raw() method.
extension Database {
func transaction(callback: @escaping (Database) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
return self.withConnection { (db) -> EventLoopFuture<Void> in
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
This file has been truncated, but you can view the full file.
#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
#yr mo dy hr mn degT m/s m/s m sec sec degT hPa degC degC degC nmi hPa ft
2019 01 24 19 48 170 15.4 17.5 MM MM MM MM 991.5 10.8 MM 10.8 1.4 MM MM
2019 01 24 19 42 170 13.9 16.0 MM MM MM MM 991.7 10.7 MM 10.7 1.2 MM MM
2019 01 24 19 36 170 11.8 19.0 MM MM MM MM 992.2 10.7 MM 10.7 1.2 MM MM
2019 01 24 19 30 180 15.4 18.0 MM MM MM MM 992.6 11.4 MM 11.4 1.2 MM MM
2019 01 24 19 24 180 15.4 20.6 MM MM MM MM 992.9 11.0 MM 11.0 1.3 MM MM
2019 01 24 19 18 180 16.5 20.6 MM MM MM MM 993.2 11.2 MM 11.2 1.4 MM MM
2019 01 24 19 12 180 16.0 19.0 MM MM MM MM 993.6 11.1 MM 11.1 2.2 MM MM
2019 01 24 19 06 180 16.0 19.6 MM MM MM MM 993.8 11.0 MM 11.0 1.5 MM MM
@samalone
samalone / DropCreateAndSeed.vb
Created December 26, 2017 19:45
Drop, create, and seed an EntityFramework database for unit testing
Imports System.Data.Entity
Imports System.Data.Entity.Migrations
Public Class DropCreateAndSeed(Of TContext As DbContext, TMigrationConfiguration As {DbMigrationsConfiguration(Of TContext), New})
Implements IDatabaseInitializer(Of TContext)
Public Sub InitializeDatabase(context As TContext) Implements IDatabaseInitializer(Of TContext).InitializeDatabase
Dim step1 = New DropCreateDatabaseAlways(Of TContext)()
step1.InitializeDatabase(context)