Skip to content

Instantly share code, notes, and snippets.

View KevinGutowski's full-sized avatar

Kevin Gutowski KevinGutowski

View GitHub Profile
@KevinGutowski
KevinGutowski / download.js
Created March 24, 2021 18:46
Async network download
let sketch = require('sketch')
var fiber = require('sketch/async').createFiber()
var url = NSURL.URLWithString("https://github.com/KevinGutowski/Testing/raw/main/Test.sketch")
let session = NSURLSession.sharedSession()
let block = __mocha__.createBlock_function('v32@?0@"NSURL"8@"NSURLResponse"16@"NSError"24', (url,response,error) => {
try {
let docError = MOPointer.alloc().init()
var newDocument = MSDocument.alloc().init();
const sketch = require("sketch");
function onDocumentChanged(context) {
var changes = context.actionContext;
for (i = 0; i < changes.length; i++) {
var change = changes[i];
var path = change.fullPath();
var type = change.type();
switch (type) {
@KevinGutowski
KevinGutowski / read.js
Last active November 1, 2021 18:30
Reading/writing a sketch file without opening it
let sketch = require('sketch')
let Document = sketch.Document
let path = "/Users/kgutowski/Downloads/Test.sketch"
let url = NSURL.fileURLWithPath(path)
let externalDoc = MSDocument.alloc().init()
externalDoc.readDocumentFromURL_ofType_error(url, "com.bohemiancoding.sketch.drawing", nil); // Be sure to capture error properly
let jsDoc = Document.fromNative(externalDoc)
console.log(jsDoc)
@KevinGutowski
KevinGutowski / LinkLabel.swift
Created January 12, 2021 09:49
Make NSTextFIeld clickable and take you to a URL
//
// LinkLabel.swift
// TestText
//
// Created by Kevin Gutowski on 1/12/21.
//
import Cocoa
@IBDesignable
@KevinGutowski
KevinGutowski / SMBMenu.swift
Created December 24, 2020 23:14
Popupmenu Plan
import Cocoa
class SMBMenu: NSMenu {
var button: NSStatusBarButton?
required init(coder: NSCoder) {
super.init(coder: coder)
}
@KevinGutowski
KevinGutowski / gistTypes.swift
Last active December 23, 2020 21:45
Swift Structs to Decode Gists API
import Foundation
// MARK: - Gist
struct Gist: Codable {
let url, forksURL, commitsURL: String
let id, nodeID: String
let gitPullURL, gitPushURL: String
let htmlURL: String
var files: [File]
let gistPublic: Bool
@KevinGutowski
KevinGutowski / decode.swift
Last active December 23, 2020 08:26
Decode JSON with Dynamic Keys using Decodable
// https://swiftsenpai.com/swift/decode-dynamic-keys-json/
// https://stackoverflow.com/questions/49549691/how-to-handle-dynamic-keys-from-json-response-using-swift-4-coding-keys
import Foundation
let json = """
{
"name": "Avengers High",
"students": {
"S001": {
@KevinGutowski
KevinGutowski / GistTypes.swift
Created December 23, 2020 03:03
Trying to figure out how to encode response into swift objects
import Foundation
struct Gist:Codable {
let url: String
let files: [File]
}
struct File:Codable {
let filename,type,language,rawURL: String
let size: Int
@KevinGutowski
KevinGutowski / fileName1.js
Created December 23, 2020 02:52
Testing the api for multiple files
console.log("hello world")
@KevinGutowski
KevinGutowski / progress.js
Last active November 25, 2020 11:42
Progressbar modal
let documentWindow = NSApplication.sharedApplication().mainWindow()
let mySheetWindow = NSWindow.alloc().initWithContentRect_styleMask_backing_defer(
NSMakeRect(0, 0, 300, 50),
(NSWindowStyleMaskTitled | NSWindowStyleMaskDocModalWindow),
NSBackingStoreBuffered,
true
)
let progressView = NSProgressIndicator
.alloc()