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 / 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 / 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 / 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 / get-unique-user-styling.js
Created November 26, 2016 03:06
Get an element's unique (non-default) styling
var getDefaultStyling = function(tagName){
if(!tagName) tagName = "dummy-tag-name";
// Create dummy iframe
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
// Create element within the iframe's document
@matt-curtis
matt-curtis / shape-layer-to-marquee.js
Last active December 3, 2015 16:58
(Sketch) Convert a shape layer to a marquee. Select both bitmap and shape layer and run the plugin.
var document = context.document;
// Find first bitmap and shape in selection
var bitmapLayer = document.selectedLayersOfClass(MSBitmapLayer)[0];
if(!bitmapLayer) return;
var shapeLayer = document.selectedLayersOfClass(MSShapeGroup)[0];
@matt-curtis
matt-curtis / export.js
Last active March 11, 2016 18:45
Export Layers in Sketch
var size = [MSExportSize sizeWithScale:4 name:"@4x" format:@"png"];
var exportRequests = [MSSliceMaker slicesFromExportableLayer:selection sizes:[ size ]];
[[MSSliceExporter new] exportSlices:exportRequests];
@matt-curtis
matt-curtis / Resizer.cocoascript.js
Last active August 29, 2015 14:26
Script for use with the default Sketch iOS App Icon Template. Takes the selected layer and duplicates it to the other artboard sizes.
var original = context.selection.firstObject();
var originalArtboard = original.parentArtboard();
var artboards = context.document.artboards();
var enumerator = artboards.objectEnumerator();
var artboard;
while((artboard = enumerator.nextObject())){
if(artboard.isEqual_(originalArtboard)) continue;
@matt-curtis
matt-curtis / NSFetchedResultsController+UICollectionView.m
Last active August 29, 2015 14:24
NSFetchedResultsController & UICollectionView using blocks (Moved Items & Deleted/Inserted Sections Fix)
@interface YourNSFetchedResultsControllerDelegate () <NSFetchedResultsControllerDelegate>
@end
@implementation YourNSFetchedResultsControllerDelegate {
UICollectionView *_collectionView;
NSMutableArray *_collectionViewUpdatesQueue;
@matt-curtis
matt-curtis / G510 Yosemite Notes.md
Last active November 23, 2016 23:30
Lenovo G510 - OS X Yosemite Install Notes
@matt-curtis
matt-curtis / MCTextFormatConverter.h
Created March 14, 2015 16:22
HTML to Attributed String & Attributed String to HTML
#import <Foundation/Foundation.h>
@interface MCTextFormatConverter : NSObject
+ (NSString*) convertTextInResponderToHTML:(UIView<UITextInput>*)view convertSelectionOnly:(BOOL)convertSelectionOnly;
+ (NSAttributedString*) htmlToAttributedString:(NSString*)html;
@end