Skip to content

Instantly share code, notes, and snippets.

View JosephDuffy's full-sized avatar
🐒
Code monkey

Joseph Duffy JosephDuffy

🐒
Code monkey
View GitHub Profile
public struct ReadableWidthView<Content: View>: UIViewControllerRepresentable {
public typealias UIViewControllerType = UIViewController
private let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
public func makeUIViewController(context: Context) -> UIViewController {
/**
Copyright 2020 Joseph Duffy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
@JosephDuffy
JosephDuffy / main-multiple-functions.swift
Last active June 4, 2020 15:48
OSLog Variadic Arguments
// A version of main.swift that is closer to https://stackoverflow.com/questions/50937765/why-does-wrapping-os-log-cause-doubles-to-not-be-logged-correctly/50942917#50942917, a linked by https://twitter.com/caseyliss/status/1268555666412765184
import Foundation
import os.log
import os
class OSLogWrapper {
func logDefaultariadicArg(_ message: StaticString, _ args: CVarArg... ) {
os_log(message, type: .default, args)
@JosephDuffy
JosephDuffy / README.md
Last active December 10, 2019 03:39
Tree Style Tab Config

Issues

The JS does not work.

Addon Settings

Appearance

Theme

@JosephDuffy
JosephDuffy / Get PNG from UIImageView.md
Last active September 11, 2019 11:01
Extracting images from a UIImageView
  1. Find UIImageView address (e.g. via view debugger)
  2. In the console: po [UIImagePNGRepresentation((UIImage *)[_address_ image]) base64EncodedStringWithOptions:0]
  3. Copy base 64 output
  4. In a terminal: pbpaste | base64 -D > image.png
@JosephDuffy
JosephDuffy / README.md
Last active February 20, 2019 16:23
fish function that uses bundler version of fastlane when available

To install add to ~/.config/fish/functions/. This can be done manually or via curl -o ~/.config/fish/functions/fastlane.fish https://gist.githubusercontent.com/JosephDuffy/596821c21b6810dd0c82639b1c6b8a64/raw/fastlane.fish

This function has 2 primary advantages:

  • No need to remember to type bundle exec before fastlane commands
  • Autocomplete will work when installed via fastlane enable_auto_complete

Disclamer: My fish scripting skills aren't exactly 💯. If you have any suggestions for improvements please tweet them at me!

@JosephDuffy
JosephDuffy / 1. StateMachine.swift
Created August 18, 2018 19:46 — forked from shaps80/1. StateMachine.swift
A lightweight generic state machine implementation in Swift.
import Foundation
import os.log
public protocol StateMachineDelegate: class {
associatedtype StateType: Hashable
/// Invoked before a transition is about to occur, allowing you to reject even a valid transition. Defaults to true
///
/// - Parameters:
import Foundation
struct Partial<Wrapped>: CustomStringConvertible, CustomDebugStringConvertible {
enum Error<ValueType>: Swift.Error {
case missingKey(KeyPath<Wrapped, ValueType>)
case invalidValueType(key: KeyPath<Wrapped, ValueType>, actualValue: Any)
}
private var values: [PartialKeyPath<Wrapped>: Any?] = [:]
@JosephDuffy
JosephDuffy / keybase.md
Last active April 21, 2018 17:26
keybase.md

Keybase proof

I hereby claim:

  • I am josephduffy on github.
  • I am josephduffy (https://keybase.io/josephduffy) on keybase.
  • I have a public key ASBeGhM8RITtTJSpJG6YexBC2RqJkf5uaM3U5jndy8vNhwo

To claim this, I am signing this object:

@JosephDuffy
JosephDuffy / ExampleViewController.swift
Last active November 30, 2022 18:28
Animates changing the brightness of a `UIScreen`
import UIKit
final class ExampleViewController: UViewController {
private var usersBrightness = UIScreen.main.brightness
private var willEnterForegroundWasCalled = false
private var viewWillDisappearWasCalled = false
override func viewDidLoad() {