Skip to content

Instantly share code, notes, and snippets.

View T1T4N's full-sized avatar
👽

Robert Armenski T1T4N

👽
View GitHub Profile
@T1T4N
T1T4N / tar.sh
Last active May 21, 2019 07:30
Tar with options (rename & exclude)
#!/usr/bin/env bash
TAR_OPTS=(
# Rename file(s)
-s ':string/in/path:replacement:g'
--exclude 'Contents/Frameworks'
)
# non-GNU tar
tar "${TAR_OPTS[@]}" \
@T1T4N
T1T4N / array_join.sh
Created June 12, 2019 06:47
Bash array join
join_by() {
# https://stackoverflow.com/a/17841619/6053417
local IFS="$1"
shift
echo "$*"
}
@T1T4N
T1T4N / ObservablePublisher.swift
Last active September 17, 2019 14:35
A generic wrapper for observing changes from a Combine Publisher - Xcode 11 GM
import Foundation
import Combine
import SwiftUI
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
class ObservablePublisher<Output>: ObservableObject {
var bag: [AnyCancellable] = []
@Published public internal(set) var value: Output?
init(erased publisher: AnyPublisher<Output, Never>) {
Fixes for common macOS Bamboo issues:
1. codesign:
/usr/bin/codesign --force --sign "HASH" --verbose file.dylib
file.dylib: replacing existing signature
file.dylib: errSecInternalComponent
Fix
Open keychain containing codesign certificate:
security unlock-keychain
@T1T4N
T1T4N / output_to_syslog.sh
Last active December 7, 2020 15:01
Bash redirect output to syslog
# As the first command in a script
exec 1> >(logger -is -t "$(basename "$0")") 2>&1
# Alternatively, output everything to a file
#exec 1> "$PWD/out.log" 2>&1
@T1T4N
T1T4N / SwiftUI+VisualEffects.swift
Created August 16, 2019 10:59
Swift embed NSHostingView in NSVisualEffectsView
// let contentView = NSHostingView(rootView: ContentView())
visualEffect.addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = true
contentView.autoresizingMask = [.width, .height]
window.contentView = visualEffect
@T1T4N
T1T4N / CustomPlainButtonStyle.swift
Created September 19, 2019 13:41
A custom ButtonStyle that extends PlainButtonStyle functionality
struct CustomPlainButtonStyle: PrimitiveButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
// reuse the original button action
Button(action: configuration.trigger, label: {
// configure the button label to our needs
configuration.label
.frame(width: 200, height: 200)
.foregroundColor(Color.red)
.background(Color.green)
})
@T1T4N
T1T4N / CaseEquatable.swift
Created September 23, 2019 15:01
Enums with Associated Values: Protocol & example implementation of matching without taking the associated value into account
protocol CaseEquatable {
associatedtype Case: Equatable
var `case`: Case { get }
static func ~=(lhs: Self, rhs: Self) -> Bool
}
extension CaseEquatable {
static func ~=(lhs: Self, rhs: Self) -> Bool {
return lhs.case == rhs.case
/**
A type-erased encodable value.
Useful in generic contexts or collections that
require mixed types conforming to
[Encodable](apple-reference-documentation://hsh65KLP6K).
*/
public struct AnyEncodable: Encodable {
/// The underlying object.
public let base: Encodable
@T1T4N
T1T4N / SetterBinding.swift
Created October 16, 2019 09:30
A Binding subscript to a read-only KeyPath that accepts a setter closure for a custom action
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension Binding {
/**
Creates a new `Binding` focused on `Subject` using a key path.
*/
public subscript<Subject>
(keyPath keyPath: KeyPath<Value, Subject>, setter: @escaping (Subject) -> Void)
-> Binding<Subject> {
.init(get: {
self.wrappedValue[keyPath: keyPath]