Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Curtis matt-curtis

View GitHub Profile
@matt-curtis
matt-curtis / DelegateForwarder.swift
Last active Mar 11, 2022
Delegate Forwarding in Swift. Useful for choosing some methods of a delegate to handle yourself and others to pass to a different delegate. Inspired by WebKit's Objective-C implementation of the same for UIScrollViewDelegate: https://github.com/WebKit/WebKit/blob/20586209d4e623ecaf489c9913a5732d80ba6e39/Source/WebKit/UIProcess/ios/WKScrollView.m…
View DelegateForwarder.swift
class DelegateForwarder<T: NSObjectProtocol>: NSObject {
// MARK: - Properties
weak var internalDelegate: T?
weak var externalDelegate: T?
var asConforming: T {
@matt-curtis
matt-curtis / SwiftUIKeyboardResizing.swift
Last active Aug 28, 2021
iOS 15 SwiftUI Keyboard Resizing (Bug?) Workaround
View SwiftUIKeyboardResizing.swift
import UIKit
import SwiftUI
class KeyboardViewController: UIInputViewController {
override func viewDidLoad() {
super.viewDidLoad()
struct ContentView: View {
@matt-curtis
matt-curtis / AnimatableMemberHaving.swift
Last active Aug 22, 2021
AnimatableMemberHaving: A protocol that enables types whose members are made up of Animatable or VectorArithmetic-conforming properties to become Animatable themselves by specifying those members
View AnimatableMemberHaving.swift
import SwiftUI
/// A protocol that enables types whose members are made up of `Animatable` or `VectorArithmetic`-conforming properties
/// to become `Animatable` themselves by specifying those members.
///
/// Here's an example of how to use this protocol:
///
/// ```
/// struct CornerRadii: AnimatableMemberHaving {
///
@matt-curtis
matt-curtis / NumberPadDoneBtn.h
Last active Dec 31, 2020
Done Button for UIKeyboard NumberPad (must be set as inputAccessoryView)
View NumberPadDoneBtn.h
#import <UIKit/UIKit.h>
@interface NumberPadDoneBtn : UIView
@end
@interface NumberPadButton : UIButton
@end
@matt-curtis
matt-curtis / 1.Info.md
Last active Dec 22, 2020
CALayer.shadowPath and CALayer.path don't overshoot when spring animated.
View 1.Info.md

Playground demonstrating CALayer.shadowPath's failure to overshoot when spring animated.

@matt-curtis
matt-curtis / linkgrabber.js
Last active Sep 13, 2020
JS Link Grabber - Uses TextArea to Acquire Links Dropped onto Pages
View linkgrabber.js
var LinkGrabber = {
textarea: null,
/* Textarea Management */
attach_ta: function(){
if(LinkGrabber.textarea != null) return;
var textarea = LinkGrabber.textarea = document.createElement("textarea");
textarea.setAttribute("style", "position: fixed; width: 100%; margin: 0; top: 0; bottom: 0; right: 0; left: 0; z-index: 99999999");
@matt-curtis
matt-curtis / LocalServer.swift
Created Mar 18, 2020
Really simple example showing how to create a basic local HTTP server in Swift
View LocalServer.swift
import Foundation
import Cocoa
private enum Constants {
static let crlf: Character = "\r\n"
}
/*
@matt-curtis
matt-curtis / MOJavaScriptObject.m
Last active Aug 22, 2019
MOJavaScriptObject function execution
View MOJavaScriptObject.m
@import JavaScriptCore;
/// Retaining MOJavaScriptObject retains your JSContext/JSObject as well
@interface MOJavaScriptObject : NSObject
@property (readonly) JSObjectRef JSObject;
@property (readonly) JSContextRef JSContext;
@matt-curtis
matt-curtis / gist:c0fa7aa820d6257e7b2a
Last active Aug 21, 2019
UINavigationBar Multiline Title
View gist:c0fa7aa820d6257e7b2a
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(!self.navigationItem.titleView){
self.navigationItem.titleView = ({
UILabel *titleView = [UILabel new];
titleView.numberOfLines = 0;
titleView.textAlignment = NSTextAlignmentCenter;
titleView.attributedText = [[NSAttributedString alloc] initWithString:@"2\nLINES" attributes:
self.navigationController.navigationBar.titleTextAttributes
View SubstringFontReporting.js
let sketch = require('sketch')
let settingsAttribute = getSettingsAttributeForKey_Value(kLowerCaseType, kLowerCaseSmallCapsSelector)
applySubstringFontModification()
//getFontAttributesForSelectedRange()
function applySubstringFontModification() {
let document = sketch.getSelectedDocument()
let textLayer = document.selectedLayers.layers[0]