Skip to content

Instantly share code, notes, and snippets.

View KevinGutowski's full-sized avatar

Kevin Gutowski KevinGutowski

View GitHub Profile
let items = [
"Cats walking down to the mall to hang out at the water fountain",
"Dogs catching tennis balls by the hotel pool",
"Fish doing backflips as they hone their circus aspirations"
]
let mainAttributedString = NSMutableAttributedString()
for (index, item) in items.enumerated() {
// Get the highest number however you want, this is hardcoded for sake of example
@krzyzanowskim
krzyzanowskim / StringGetSizeThatFits.swift
Last active November 12, 2023 14:51
Calculate frame of String, that fits given width
// Excerpt from https://github.com/krzyzanowskim/CoreTextWorkshop
// Licence BSD-2 clause
// Marcin Krzyzanowski marcin@krzyzanowskim.com
func getSizeThatFits(_ attributedString: NSAttributedString, maxWidth: CGFloat) -> CGSize {
let framesetter = CTFramesetterCreateWithAttributedString(attributedString)
let rectPath = CGRect(origin: .zero, size: CGSize(width: maxWidth, height: 50000))
let ctFrame = CTFramesetterCreateFrame(framesetter, CFRange(), CGPath(rect: rectPath, transform: nil), nil)
@christianklotz
christianklotz / sketch-load-json.js
Created March 19, 2019 15:59
Load JSON file into Sketch
let readBinaryFile = (filepath) => {
return NSData.alloc().initWithContentsOfFile(filepath);
};
let path = "path/to/file.json"
let data = readBinaryFile(path)
let contents = NSString.alloc().initWithData_encoding(data, NSUTF8StringEncoding)
console.log(JSON.parse(contents))
@beesandbombs
beesandbombs / wavingCubes.pde
Created September 11, 2017 22:23
waving cubes
// gif by dave @beesandbombs :)
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
@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;