Skip to content

Instantly share code, notes, and snippets.

Avatar
🐒
Code monkey

Joseph Duffy JosephDuffy

🐒
Code monkey
View GitHub Profile
View ReadableWidthView.swift
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 {
View Binding+mappedToBool.swift
/**
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
View main-multiple-functions.swift
// 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 Dec 10, 2019
Tree Style Tab Config
View README.md

Issues

The JS does not work.

Addon Settings

Appearance

Theme

@JosephDuffy
JosephDuffy / Get PNG from UIImageView.md
Last active Sep 11, 2019
Extracting images from a UIImageView
View Get PNG from UIImageView.md
  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 Feb 20, 2019
fish function that uses bundler version of fastlane when available
View README.md

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 Aug 18, 2018 — forked from shaps80/1. StateMachine.swift
A lightweight generic state machine implementation in Swift.
View 1. StateMachine.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:
View Partial.swift
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?] = [:]
View 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 Aug 10, 2021
Animates changing the brightness of a `UIScreen`
View ExampleViewController.swift
import UIKit
final class ExampleViewController: UViewController {
private var usersBrightness = UIScreen.main.brightness
private var willEnterForegroundWasCalled = false
private var viewWillDisappearWasCalled = false
override func viewDidLoad() {