Skip to content

Instantly share code, notes, and snippets.

View plu's full-sized avatar
🏠
Working from home

Johannes Plunien plu

🏠
Working from home
  • Kleinanzeigen
  • Germany
View GitHub Profile
#!/bin/sh
# This is an example script to force provision a UniFi network device using the controller API
# If you are running this externally then replace localhost with the hostname
baseurl=https://localhost:8443
# I would make a dedicated admin user for this
username=<username_here>
password=<password_here>
@pudquick
pudquick / brew.md
Last active June 24, 2024 19:41
Lightly "sandboxed" homebrew on macOS

brew is a bad neighbor

This isn't a guide about locking down homebrew so that it can't touch the rest of your system security-wise.

This guide doesn't fix the inherent security issues of a package management system that will literally yell at you if you try to do something about "huh, maybe it's not great my executables are writeable by my account without requiring authorization first".

But it absolutely is a guide about shoving it into its own little corner so that you can take it or leave it as you see fit, instead of just letting the project do what it likes like completely taking over permissions and ownership of a directory that might be in use by other software on your Mac and stomping all over their contents.

By following this guide you will:

  • Never have to run sudo to forcefully change permissions of some directory to be owned by your account
@varac
varac / gist:0e16de606828968b30f0cd247ed79cbc
Created February 6, 2021 13:39
Export restic prometheus metrics
#!/bin/bash
# based on https://medium.com/@zoispag/collect-restic-metrics-when-using-resticker-cf862f87fc41
# This script will execute restic commands and will pipe the output to jq,
# in order to format it in a prometheus compatible metric.
# Add this script in the host crontab, to be executed every few hours.
HOST=${HOST:-`hostname -f`}
# Ensure jq package is installed, as it is needed to format
@keith
keith / README.md
Last active January 9, 2024 07:52
A test of `@_dynamicReplacement` in Swift

Usage

  1. swiftc main.swift -emit-module-path main.swiftmodule -emit-executable -enable-private-imports -Xfrontend -enable-implicit-dynamic
  2. ./main -> prints From original bar()
  3. swiftc -emit-library inject.swift -o inject.dylib -I . -Xlinker -undefined -Xlinker suppress -Xlinker -flat_namespace -Xfrontend -disable-access-control
  4. DYLD_INSERT_LIBRARIES=inject.dylib ./main -> prints From replacement bar()

Notes

  • Passing -Xfrontend -enable-implicit-dynamic removes you from having to add dynamic to everything you want to be replacable
@lg
lg / adding-tailscale-to-edgerouter.md
Last active April 11, 2024 07:44
Add tailscale to an EdgeRouter and surviving system upgrade

Adding tailscale to an EdgeRouter (and surviving system upgrades)

I suggest you run sudo bash on all of these so you're the root user.

Installing

  1. Download tailscale and put the files in /config/. Find the latest stable or unstable version for your EdgeRouter's processor (ex. ER4 is mips and ERX is mipself)
sudo bash    # if you havent already
@propertyWrapper
public final class LayoutInvalidating<Value> where Value: Equatable {
public static subscript<EnclosingSelf>(
_enclosingInstance observed: EnclosingSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, LayoutInvalidating>
) -> Value where EnclosingSelf: UIView {
get {
return observed[keyPath: storageKeyPath].stored
@mjm
mjm / LinkedText.swift
Created May 21, 2020 03:56
Tappable links in SwiftUI Text view
import SwiftUI
private let linkDetector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
struct LinkColoredText: View {
enum Component {
case text(String)
case link(String, URL)
}
import UIKit
import SafariServices
import AuthenticationServices
import AppAuth
import Reachability
class OIDExternalUserAgentASWebAuthenticationSession: NSObject, OIDExternalUserAgent {
private let presentingViewController: UIViewController
private var externalUserAgentFlowInProgress: Bool = false
private var authenticationViewController: ASWebAuthenticationSession?
@george-lim
george-lim / swiftlint.sh
Created January 20, 2020 00:58
A handy Xcode run script that applies SwiftLint only to new Swift codebase changes
#!/bin/bash
# Parameters
source="$(pwd)/$1" # Track folder source where diffs are checked
index=$2 # Track diff remote
project_root=${0%/*} # Track project root folder
swiftlint_path='Pods/SwiftLint/swiftlint' # Track SwiftLint path
# Parameter check
if [[ $# < 1 ]]; then
@crewshin
crewshin / KeyboardAvoiding.swift
Last active March 21, 2024 13:55
KeyboardAvoiding SwiftUI
import SwiftUI
class KeyboardAvoidingHostingController<Content>: UIHostingController<Content> where Content: View {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)