Skip to content

Instantly share code, notes, and snippets.

View drekka's full-sized avatar
🏍️
Brrrrrm

Derek Clarkson drekka

🏍️
Brrrrrm
  • Melbourne, Australia
View GitHub Profile
@drekka
drekka / freeadmin.sh
Last active December 21, 2023 03:34
Creates an hidden admin user
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
echo "Warning: you are about to create a hidden admin user!"
read -p "New admin user ID: " user_id
extension Encodable {
// This lets any encodable encode itself into a container.
fileprivate func encode(to container: inout SingleValueEncodingContainer) throws {
try container.encode(self)
}
}
// This wraps an encodable so it can be encoded. It uses the above extension so that the
// we don't have to know the encodable's type.
struct AnyEncodable : Encodable {
@drekka
drekka / PublishingAppStorage.swift
Last active October 23, 2023 20:15
A wrapper for SwiftUI @AppStorage that also provides a Publisher for non-View types to receive updates.
/// Property wrapper that acts the same as @AppStorage, but also provides a ``Publisher`` so that non-View types
/// can receive value updates.
@propertyWrapper
struct PublishingAppStorage<Value> {
var wrappedValue: Value {
get { storage.wrappedValue }
set {
storage.wrappedValue = newValue
subject.send(storage.wrappedValue)