Skip to content

Instantly share code, notes, and snippets.

@joethephish
joethephish / PromptWindowController.swift
Last active April 2, 2025 17:37
Substage's flippy out command bar
import AppKit
import SwiftUI
class PromptWindowController: NSWindowController, NSWindowDelegate {
// Essential properties
private var promptWindowContext: PromptWindowContext
private let finderContext: FinderContext
init() {
@joethephish
joethephish / text-field-with-colour.swift
Last active November 16, 2024 19:17
Sample code for how to highlight text within a TextField in SwiftUI in my app
TextField(placeholder, text:$event.title, axis: Axis.vertical)
.keyboardType(.default)
.focused($textFieldFocus, equals:controlId)
// When newline is detected, create a new item (or delete if it's empty)
// We'd do this in onKeyPress(.return) but that's only for hardware keyboards
.lineLimit(100, reservesSpace: false)
.overlay(alignment: Alignment(horizontal:.leading, vertical: .center)) {
GeometryReader { proxy in
@joethephish
joethephish / PlatformFloat.cs
Created July 1, 2020 16:40
Class to wrap single tweakable float value for UI that depends on platform. Could be hacked/adapted for something other than input type/platform.
using System;
using UnityEngine;
/// <summary>
/// PlatformFloat is an easy way of providing platform-specific tweak values.
/// By default, it behaves exactly like a normal float, and is converted back and forth
/// from a normal float implicitly.
/// However, in the inspector its possible to use a dropdown to provide platform
/// specific values for desktop, gamepad and touch.
/// </summary>
@joethephish
joethephish / map.ink
Created May 24, 2020 14:53
Sorcery-style ink with MAP convention
-> locationA
// Maybe in locationA.ink?
== locationA ==
Hello, welcome to location A!
-
+ Look in the drawer! -> lookInDrawer
+ Don't bother -> locationAPart2
= lookInDrawer
@joethephish
joethephish / ts-check-bug-simpler.js
Last active December 19, 2019 15:18
Default param causes ts-check to fail
const Obj = {
x: 1,
f: (y = Obj.x) => {}
};
Obj.x; // No definition found for 'x'
@joethephish
joethephish / ExampleTextView.cs
Created November 22, 2018 13:17
Example of centre alignment using SLayout
public class ExampleTextView {
public bool alignCentre;
// ... various fields, grab the SLayout as "layout" ...
// populate this list
List<SLayout> _wordLayouts;
// Lays out the words and returns the size used.
@joethephish
joethephish / simple-ink-story.ink
Created July 14, 2018 13:55
Simple ink story example
LONDON, 1872
Residence of Monsieur Phileas Fogg.
-> london
=== london ===
Monsieur Phileas Fogg returned home early from the Reform Club, and in a new-fangled steam-carriage, besides!
"Passepartout," said he. "We are going around the world!"
+ "Around the world, Monsieur?"
@joethephish
joethephish / Exp_for_zooming.md
Last active March 12, 2018 01:36
Using Mathf.Exp for zooming

Using Exp for zooming

One of the things I’m happiest to have learned in the past few months is a great use for Log + Exp in games when zooming in and out.

You may have already know that linear speeds work horribly for zooming, e.g.:

void Update() {
    scale = scale + speed * Time.deltaTime;
}
@joethephish
joethephish / XKCD_Calendar_Facts.ink
Last active December 18, 2017 17:04
An implementation in ink of https://xkcd.com/1930/
Did you know that {something()} {happens()} {becauseOf()}? {apparently()}.
== function something ==
{~
- the {~fall|spring} equinox
- the {~winter|summer} {~solstice|olympics}
- the {~earliest|latest} {~sunrise|sunset}
- daylight {~saving|savings} time
- leap {~days|years}
@joethephish
joethephish / MiniList.cs
Last active January 11, 2018 10:29
MiniList<T> - a struct based IList to be used when you have a very small number of elements
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Similar to normal List<T> except that it's a struct, meaning a local instance doesn't allocate any memory
/// on the heap by default. It has enough capacity for 8 items, beyond which point it'll automatically allocate
/// a full list internally. Useful if you want to have a list with a small number of items, and you don't want
/// any churn in the heap as a result. It'll be a bit slower than a normal list or array though since it needs
/// to do at least one switch statement any time you access it. Although it'll upgrade itself to a full list