Skip to content

Instantly share code, notes, and snippets.

deviceUdid=$(xcrun simctl create "my_simulator" "${IOS_DEVICE}" "iOS${IOS_VERSION}")
alias plistBuddy=/usr/libexec/PlistBuddy
simPrefs="$HOME/Library/Preferences/com.apple.iphonesimulator.plist"
plistBuddy -c "Set :DevicePreferences:$deviceUdid:ConnectHardwareKeyboard false" "$simPrefs" \
|| plistBuddy -c "Add :DevicePreferences:$deviceUdid:ConnectHardwareKeyboard bool false" "$simPrefs";
@samrayner
samrayner / console-script.js
Created May 2, 2022 10:24
Delete Github Comments
Array.prototype.forEach.call(document.querySelectorAll('.timeline-comment-action'), function(el, i) {
el.click();
});
Array.prototype.forEach.call(document.querySelectorAll('button[aria-label="Delete comment"]'), function(el, i) {
el.removeAttribute('data-confirm');
el.click();
});
import Foundation
///A type that can be encoded to a string-keyed dictionary.
public protocol DictionaryEncodable: Encodable {}
public protocol DictionaryDecodable: Decodable {}
///A type that can be encoded and decoded to/from a string-keyed dictionary.
public typealias DictionaryCodable = DictionaryEncodable & DictionaryDecodable
extension DictionaryEncodable {
/*
Why?
- Lots of RawRepresentable boilerplate for every enum that needs a .other() case
- The model is polluted with an invalid case which we can't define behaviour for other than logging
- New method lets us handle the invalid case (e.g. log it) but then only pass on valid cases to the rest of the app
*/
import Foundation
enum RawExpectation<Expected: RawRepresentable> {
@samrayner
samrayner / Realm+CascadeDeleting.swift
Last active June 24, 2021 10:38 — forked from krodak/Realm+CascadeDeleting.swift
Cascading deletion for RealmSwift
import Foundation
import RealmSwift
import Realm
//Forked from: https://gist.github.com/krodak/b47ea81b3ae25ca2f10c27476bed450c
internal protocol CascadingDeletable: RealmSwift.Object {
static var propertiesToCascadeDelete: [String] { get }
}
➜ ~ xcode-select -p
/Applications/Xcode-beta.app/Contents/Developer
➜ ~
➜ ~ echo "import Foundation;print(Date())" | xcrun swift -
Stack dump:
0. Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret - -enable-objc-interop -stack-check -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main
1. Apple Swift version 5.2 (swiftlang-1103.0.25.1 clang-1103.2.32.5)
2. While running user code "<stdin>"
0 swift 0x000000010ab72033 PrintStackTraceSignalHandler(void*) + 51
1 swift 0x000000010ab717f0 SignalHandler(int) + 352
//
// RunTimeTheme.swift
// RunTimeTheme.swift
//
// Created by Sam Rayner on 24/10/2018.
// Copyright © 2018 Sam Rayner. All rights reserved.
//
import UIKit
import Foundation
extension UserDefaults {
enum Key: String {
case customKey
}
//can be used for KVO
@objc dynamic var customKey: Int {
return get(.customKey) ?? 0
#!/bin/bash
#Help to display if the args are wrong
usage() { echo "Usage: $0 -o path/to/output.json" 1>&2; exit 1; }
#Show help if the args are wrong
while getopts ":o:" ARG; do
case "${ARG}" in
o)
OUTPUT_FILE=${OPTARG}
@samrayner
samrayner / XibView.swift
Last active August 19, 2016 10:17
Xib-backed UIView subclass. Set the class name and outlets on the view's owner, not on the view itself!
//
// XibView.swift
//
//
// Created by Sam Rayner on 29/05/2016.
// Copyright © 2016 Sam Rayner. All rights reserved.
//
import UIKit