Skip to content

Instantly share code, notes, and snippets.

View shawnkoh's full-sized avatar

Shawn Koh shawnkoh

View GitHub Profile
@willmcgugan
willmcgugan / stopwatch.css
Created August 23, 2022 13:30
Examples application in Textual introduction
Stopwatch {
layout: horizontal;
background: $panel-darken-1;
height: 5;
min-width: 50;
margin: 1;
padding: 1;
}
TimeDisplay {
@tgrapperon
tgrapperon / JuxtaposedView.swift
Last active November 16, 2022 17:21
SwiftUI modifier to juxtapose a view to a root view without affecting the layout of the root view.
import SwiftUI
public extension View {
func juxtapose<Content>(
edge: Edge = .top,
spacing: CGFloat = 8,
@ViewBuilder content: @escaping () -> Content
) -> some View where Content: View {
modifier(
JuxtaposedViewModifier(
@krzysztofzablocki
krzysztofzablocki / debugDiffing.swift
Created August 18, 2021 18:28
Higher order reducer for TCA that enables better debugging
import ComposableArchitecture
import Difference
import Foundation
/// A container for storing action filters.
///
/// The logic behind having this rather than a normal closure is that it allows us to namespace and gather action filters together in a consistent manner.
/// - Note: You should be adding extensions in your modules and exposing common filters you might want to use to focus your debugging work, e.g.
/// ```swift
/// extension ActionFilter where Action == AppAction {
extension Result {
func tryMap<T>(_ transform:(Success) throws -> T) -> Result<T, Swift.Error> {
switch self {
case let .success(success):
do {
return .success(try transform(success))
} catch {
return .failure(error)
}
case let .failure(failure):
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@chriseidhof
chriseidhof / sample.swift
Last active February 25, 2024 16:04
View Inspection
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
@chriseidhof
chriseidhof / collectionview.swift
Last active January 31, 2024 19:00
SwiftUI Flow Layout
//
// ContentView.swift
// DeleteMe
//
// Created by Chris Eidhof on 02.02.21.
//
import SwiftUI
/*
@morishin
morishin / left-align-stack-view.png
Last active March 22, 2024 00:25
Align to Left the contents of UIStackView
left-align-stack-view.png
@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active April 30, 2024 23:36
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName