Skip to content

Instantly share code, notes, and snippets.

View matt-curtis's full-sized avatar

Matt Curtis matt-curtis

View GitHub Profile
@matt-curtis
matt-curtis / SwiftUIKeyboardResizing.swift
Last active February 27, 2023 11:23
iOS 15 SwiftUI Keyboard Resizing (Bug?) Workaround
import UIKit
import SwiftUI
class KeyboardViewController: UIInputViewController {
override func viewDidLoad() {
super.viewDidLoad()
struct ContentView: View {
@matt-curtis
matt-curtis / linkgrabber.js
Last active November 9, 2022 22:17
JS Link Grabber - Uses TextArea to Acquire Links Dropped onto Pages
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 / DelegateForwarder.swift
Last active March 11, 2022 22:23
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…
class DelegateForwarder<T: NSObjectProtocol>: NSObject {
// MARK: - Properties
weak var internalDelegate: T?
weak var externalDelegate: T?
var asConforming: T {
@matt-curtis
matt-curtis / AnimatableMemberHaving.swift
Last active August 22, 2021 02:24
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
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 December 31, 2020 14:29
Done Button for UIKeyboard NumberPad (must be set as inputAccessoryView)
#import <UIKit/UIKit.h>
@interface NumberPadDoneBtn : UIView
@end
@interface NumberPadButton : UIButton
@end
@matt-curtis
matt-curtis / 1.Info.md
Last active December 22, 2020 20:47
CALayer.shadowPath and CALayer.path don't overshoot when spring animated.

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

@matt-curtis
matt-curtis / LocalServer.swift
Created March 18, 2020 14:16
Really simple example showing how to create a basic local HTTP server in Swift
import Foundation
import Cocoa
private enum Constants {
static let crlf: Character = "\r\n"
}
/*
@matt-curtis
matt-curtis / MOJavaScriptObject.m
Last active August 22, 2019 07:13
MOJavaScriptObject function execution
@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 August 21, 2019 13:49
UINavigationBar Multiline Title
- (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
let sketch = require('sketch')
let settingsAttribute = getSettingsAttributeForKey_Value(kLowerCaseType, kLowerCaseSmallCapsSelector)
applySubstringFontModification()
//getFontAttributesForSelectedRange()
function applySubstringFontModification() {
let document = sketch.getSelectedDocument()
let textLayer = document.selectedLayers.layers[0]