Skip to content

Instantly share code, notes, and snippets.

View jamesporter's full-sized avatar

James Porter jamesporter

View GitHub Profile
@jamesporter
jamesporter / ContentView.swift
Created April 17, 2024 21:59
Metal and Swift(UI) Raymarching App
import SwiftUI
struct ContentView: View {
let startDate = Date()
var body: some View {
GeometryReader { gp in
TimelineView(.animation) { ctx in
Rectangle()
.ignoresSafeArea()
@jamesporter
jamesporter / SwiftUIPretendLatexEditor.swift
Created June 13, 2023 20:42
Equation Editing in SwiftUI with Swift Math
import SwiftUI
import SwiftMath
enum ContentItem: Identifiable {
case text(_ text: String, id: Int)
case equation(_ equation: String, id: Int)
// this is obviously very simplistic/needs improvement if to be used for reals
static func parse(input: String) -> [ContentItem] {
let items = input.split(separator: "$$\n")
@jamesporter
jamesporter / NiceLazyVGridLayout.swift
Last active November 5, 2023 16:50
Nice LazyVGrid layout
// 1. Set up adapative items (repeat, with min/max width), then add spacing as second argument to GridItem:
var columns = [GridItem(.adaptive(minimum: 240, maximum: 420), spacing: spacing)]
var body: some View {
VStack {
ScrollView {
LazyVGrid(columns: columns, spacing: spacing) { // 4. also add spacing here (between rows)
ForEach(document.state.cards) { card in
// 2. Item, then with heights that take full width + some fixed height:
import SwiftUI
extension String {
var asAttributedMarkdown: AttributedString {
do {
return try AttributedString(markdown: self, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))
} catch {
return AttributedString(stringLiteral: self)
}
}
@jamesporter
jamesporter / LexicalSwiftUIPoC.swift
Created April 6, 2023 21:26
Lexical iOS SwiftUI integration PoC
import SwiftUI
import Lexical
struct ContentView: View {
@StateObject var store = LexicalStore()
var body: some View {
VStack {
import SwiftUI
extension View {
func unfuckText() -> some View {
fixedSize(horizontal: false, vertical: true)
}
}
@jamesporter
jamesporter / build.js
Created March 26, 2023 20:35
Convert Sonic Pi Tutorial to epub
const fs = require("fs");
const path = require("path");
const mds = fs.readdirSync("./").filter((f) => f.includes(".md"));
let contents = `
---
title: Sonic Pi Tutorial
author: Sam Aaron
...
@jamesporter
jamesporter / Share.swift
Created May 8, 2022 10:55
Share Sheet in SwiftUI
.sheet(isPresented: $isSharing) {
AppActivityView(activityItems: ["something", URL(string: "https://apps.apple.com/us/app/deadly-divisors/id888788693")!])
}
@jamesporter
jamesporter / CustomFont.swift
Created May 8, 2022 09:23
Adding Noto Emoji to iOS (etc) app
import SwiftUI
enum CustomFont {
static let notoEmoji = "NotoEmoji-SemiBold"
}
struct Emoji: View {
var text: String
var size: CGFloat
@jamesporter
jamesporter / keys.swift
Created April 3, 2022 23:08
Wordle Words in a Swift File
import Foundation
let rawKeys = [
["q","w","e","r","t","y","u","i","o","p"],
["a","s","d","f","g","h","j","k","l"],
["z","x","c","v","b","n","m"]
]
enum InputKey: Hashable, Equatable, Codable {
case letter(key: String)