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 / accept-all-suggestions.js
Created February 28, 2017 21:23
Google Docs - Accept all suggestions
function run(){
var shouldRun = confirm("Are you sure you want to accept all suggestions?\n\n(Note: Depending on the number of suggestions you have, this script may take a few seconds to run.)");
if(!shouldRun) return false;
var events = [ "mouseover", "mousedown", "click", "mouseup" ];
var suggestionButtons = Array.from(document.querySelectorAll("[role='button'][aria-label='Accept suggestion']"));
suggestionButtons.forEach((el) => {
events.forEach((eventName, i) => {
@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 / OptionSet.swift
Last active November 25, 2017 15:08
(Better?) OptionSet
struct Traits: OptionSet {
var rawValue: Int = 0
init(rawValue: Int) {
self.rawValue = rawValue
}
}
@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)
@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 / 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 / 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 / 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();
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 / 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"
}
/*