Skip to content

Instantly share code, notes, and snippets.

View KevinGutowski's full-sized avatar

Kevin Gutowski KevinGutowski

View GitHub Profile
@KevinGutowski
KevinGutowski / getCrashes.js
Last active May 5, 2021 04:02
Get Sketch Crash Log FilePaths
let path = NSHomeDirectory() + '/Library/Logs/DiagnosticReports/'
let fileManager = NSFileManager.defaultManager()
let files = fileManager.contentsOfDirectoryAtPath_error(path,nil)
let fileNames = []
for (let i=0; i<files.count();i++) {
fileNames.push(files[i])
}
let dateFormatter = NSDateFormatter.alloc().init()
dateFormatter.dateStyle = NSDateFormatterMediumStyle
@KevinGutowski
KevinGutowski / Integration as summation
Created April 5, 2021 23:21
Example MathML output from KaTeX
<!--
Integration as summation
GS LaTeX Code
$$$
\int_a^bf(x)dx = lim_{n\to\infty}\sum_{r=1}^nhf(a+rh)
$$$
$$$
\text{where} \quad h=\frac{b-a}{n}
@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