Skip to content

Instantly share code, notes, and snippets.

View lzell's full-sized avatar

Lou Zell lzell

View GitHub Profile
@lzell
lzell / catch_foundation.swift
Last active October 7, 2024 19:08
How to catch a Foundation timeout
import AIProxy
let openAIService = AIProxy.openAIService(
partialKey: "partial-key-from-your-developer-dashboard",
serviceURL: "service-url-from-your-developer-dashboard"
)
do {
let response = try await openAIService.chatCompletionRequest(body: .init(
model: "o1-mini",
@lzell
lzell / StabilityUltra.swift
Last active July 31, 2024 05:04
StabilityUltra.swift
import Foundation
import SwiftUI
import AIProxy
final actor ImageLoader {
static func create(fromPrompt prompt: String) async -> UIImage? {
let service = AIProxy.stabilityAIService(
partialKey: "your-partial-key",
serviceURL: "your-service-url")
do {
@lzell
lzell / modern_wwd_crash_course_notes.txt
Created March 21, 2024 00:59
modern_wwd_crash_course_notes.txt
## WWDC notes
2019 Introducing SwiftUI
- Views are structs, value types, passed by value, allocated on the stack.
- If you have something like `let room: Room` as a property, and Room is a
struct, then the surrounding struct has "the size and weight of a room, no
additional allocation or reference counting overhead"
- 17:30
"make liberal use of small, single purpose views in SwiftUI"
"views in SwiftUI are incredibly lightweight"
@lzell
lzell / DoesThisSwiftUILeak.md
Created January 7, 2024 19:29
Inspecting if dependency on Observable leaks in SwiftUI

Contents of MyApp.swift

import SwiftUI

@main
struct AnimateOnObservedPropertyChangeApp: App {
    @State var trigger = false

    var body: some Scene {
@lzell
lzell / figma_1.67_to_1.68.diff
Created June 24, 2023 15:27
Figma plugin API diff between versions 1.67 and 1.68
diff --git a/plugin-typings/plugin-api.d.ts b/plugin-typings/plugin-api.d.ts
index d299a90..c4ea706 100644
--- a/plugin-typings/plugin-api.d.ts
+++ b/plugin-typings/plugin-api.d.ts
@@ -12,7 +12,8 @@ declare type ArgFreeEventType =
interface PluginAPI {
readonly apiVersion: '1.0.0'
readonly command: string
- readonly editorType: 'figma' | 'figjam'
+ readonly editorType: 'figma' | 'figjam' | 'dev'
@lzell
lzell / figma_plugin_setup_esbuild.md
Last active May 18, 2023 17:11
Figma plugin setup for bundling multiple source files

2023-05-17

(figma plugin, getting started)

  • Open the Figma desktop app

  • Go to Plugins > Development > New Plugin > Figma Design > Run Once
    This creates a plugin with starter source code to drop five orange rectangles on the canvas

  • Setup the plugin:

    cd <project-dir>
    
@lzell
lzell / xctesting_in_repl_or_script.swift
Created August 11, 2016 20:01
Using XCTest in the swift repl or standalone script
// Start repl with:
// $ xcrun swift -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks
// Or run as script:
// $ xcrun swift -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks %
import Foundation
if dlopen("/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework/Versions/A/XCTest", RTLD_NOW) == nil {
@lzell
lzell / dns_resolve_multicast.swift
Created June 21, 2016 21:52
DNS resolve multicast os x
var res : __res_9_state = __res_9_state()
res_9_ninit(&res)
var addr: in_addr = in_addr()
inet_aton("224.0.0.251", &addr)
res.nsaddr_list.0.sin_addr = addr
res.nsaddr_list.0.sin_family = sa_family_t(AF_INET)
res.nsaddr_list.0.sin_port = in_port_t(5353).bigEndian
res.nscount = 1
@lzell
lzell / string_to_data_back.swift
Last active September 23, 2019 19:28
Swift string to data (bytes) and back
// (string, swift, bytes, data, buffer, cstring)
print("--- using nulTerminated ---")
let x : String = "hello"
let buf = x.nulTerminatedUTF8
print(buf)
print("\n--- using [UInt8] ---")
let buf2 : [UInt8] = [UInt8](x.utf8)
print(buf2)
@lzell
lzell / JPUtils.m
Created October 9, 2012 03:39
JPUtils implementation
#import "JPUtils.h"
extern void
JPUpdateDelegates(id<JPManagerDelegate,JPDeviceDelegate> aDelegate)
{
JPManager *manager = [JPManager sharedManager];
[manager setDelegate:aDelegate];
for(JPDevice *dev in [manager connectedDevices])
{
[dev setDelegate:aDelegate];