Skip to content

Instantly share code, notes, and snippets.

View jamesporter's full-sized avatar

James Porter jamesporter

View GitHub Profile
@jamesporter
jamesporter / hello_inky_frame.py
Created December 26, 2025 16:16
Little hello-colours for Inky Frame
import inky_frame
import random
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY
graphics = PicoGraphics(DISPLAY)
graphics.set_pen(inky_frame.WHITE)
graphics.clear()
for x in range(30):
@jamesporter
jamesporter / MVP under desk shelf.js
Created December 21, 2025 22:59
WIP on a parametric under desk shelf
const { makeBox, draw, drawCircle, drawRectangle, makePlane, makeCylinder, EdgeFinder } = replicad;
export const defaultParams = {
depth: 120,
width: 300
};
function createScrewHole(h) {
return draw()
.hLine(1.5).vLine(h - 3).lineTo([3.5, h]).hLine(-3.5)
const { makeBox, draw, drawCircle, drawRectangle, makePlane, makeCylinder, EdgeFinder } = replicad;
export const defaultParams = {
depth: 120,
width: 30
};
function createScrewHole(h) {
return draw()
.hLine(1.5).vLine(h - 3).lineTo([3.5, h]).hLine(-3.5)
@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
...