Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Curtis matt-curtis

View GitHub Profile
@matt-curtis
matt-curtis / OptionSet.swift
Last active Nov 25, 2017
(Better?) OptionSet
View OptionSet.swift
struct Traits: OptionSet {
var rawValue: Int = 0
init(rawValue: Int) {
self.rawValue = rawValue
}
}
@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 / accept-all-suggestions.js
Created Feb 28, 2017
Google Docs - Accept all suggestions
View accept-all-suggestions.js
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 Nov 26, 2016
Get an element's unique (non-default) styling
View get-unique-user-styling.js
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 Dec 3, 2015
(Sketch) Convert a shape layer to a marquee. Select both bitmap and shape layer and run the plugin.
View shape-layer-to-marquee.js
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 Mar 11, 2016
Export Layers in Sketch
View export.js
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 Aug 29, 2015
Script for use with the default Sketch iOS App Icon Template. Takes the selected layer and duplicates it to the other artboard sizes.
View Resizer.cocoascript.js
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 Aug 29, 2015
NSFetchedResultsController & UICollectionView using blocks (Moved Items & Deleted/Inserted Sections Fix)
View NSFetchedResultsController+UICollectionView.m
@interface YourNSFetchedResultsControllerDelegate () <NSFetchedResultsControllerDelegate>
@end
@implementation YourNSFetchedResultsControllerDelegate {
UICollectionView *_collectionView;
NSMutableArray *_collectionViewUpdatesQueue;
@matt-curtis
matt-curtis / G510 Yosemite Notes.md
Last active Nov 23, 2016
Lenovo G510 - OS X Yosemite Install Notes
View G510 Yosemite Notes.md
@matt-curtis
matt-curtis / MCTextFormatConverter.h
Created Mar 14, 2015
HTML to Attributed String & Attributed String to HTML
View MCTextFormatConverter.h
#import <Foundation/Foundation.h>
@interface MCTextFormatConverter : NSObject
+ (NSString*) convertTextInResponderToHTML:(UIView<UITextInput>*)view convertSelectionOnly:(BOOL)convertSelectionOnly;
+ (NSAttributedString*) htmlToAttributedString:(NSString*)html;
@end