Skip to content

Instantly share code, notes, and snippets.

@aglee
aglee / AoC2018Day07.swift
Created December 7, 2018 21:09
Advent of Code Day 07
import Foundation
let USING_TEST_INPUT = false
let commandURL = URL(fileURLWithPath: CommandLine.arguments[0])
let inputFileName = USING_TEST_INPUT ? "test.txt" : "input.txt"
let inputFileURL = commandURL.deletingLastPathComponent().appendingPathComponent(inputFileName)
let inputText = try! String(contentsOf: inputFileURL, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines)
let inputLines = inputText.split(separator: "\n")
@aglee
aglee / alert-build-succeeded.swift
Created June 23, 2024 23:09
Swift program to display an alert
import Cocoa
func imageFromEmoji(emoji: String, size: CGSize) -> NSImage? {
let image = NSImage(size: size)
image.lockFocus()
let attributes: [NSAttributedString.Key: Any] = [
.font: NSFont.systemFont(ofSize: size.height) // Adjust font size based on image size
]
let attributedString = NSAttributedString(string: emoji, attributes: attributes)