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 / 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 / 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"
}
/*
let sketch = require('sketch')
let settingsAttribute = getSettingsAttributeForKey_Value(kLowerCaseType, kLowerCaseSmallCapsSelector)
applySubstringFontModification()
//getFontAttributesForSelectedRange()
function applySubstringFontModification() {
let document = sketch.getSelectedDocument()
let textLayer = document.selectedLayers.layers[0]
@matt-curtis
matt-curtis / example.js
Created January 27, 2019 02:56
Applying attributes to a text layer that's being edited in Sketch
framework("CoreText");
const DOM = require("sketch/dom");
const textLayer = DOM.getSelectedDocument().pages[0].selectedLayers.layers[0];
const textView = textLayer.sketchObject.editingDelegate().textView();
// [NSTextView selectedRanges] returns an NSArray of NSValues:
const selectedRange = textView.selectedRanges()[0].rangeValue();
@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 / UnitBezier.swift
Last active December 24, 2018 19:14
UnitBezier.swift
//
// UnitBezier.swift
//
// Created by Matt Curtis on 12/24/18.
// Copyright © 2018 Matt Curtis. All rights reserved.
//
import Foundation
// Almost exact translation of WebKit's UnitBezier struct:
@matt-curtis
matt-curtis / FontSpike.js
Last active December 18, 2018 16:37 — forked from KevinGutowski/FontSpike.js
Testing to see if I can build an Opentype Panel
framework("CoreText");
const document = require("sketch").getSelectedDocument();
const textLayer = document.selectedLayers.layers[0];
// WORKS (System font has native support for small caps):
const font = NSFont.systemFontOfSize_weight(28, NSFontWeightBold);
@matt-curtis
matt-curtis / Lenovo G510 High Sierra Notes.md
Last active February 10, 2019 06:05
Lenovo G510 High Sierra Notes

Checklist:

  • ✅ WIFI
  • ✅ Ethernet
  • ✅ Display
  • ✅ Touchpad
  • ✅ USB (2 & 3)
  • ❓ HDMI (Video works, haven't bothered to fix audio yet)
  • ✅ Sleep
  • ✅ Audio (No microphone)