Skip to content

Instantly share code, notes, and snippets.

View AndyQ's full-sized avatar

Andy Qua AndyQ

View GitHub Profile
@ryanlintott
ryanlintott / View+ifAvailable.swift
Last active March 4, 2025 15:50
A conditional SwiftUI view extension that can be used to optionally apply view modifiers based on OS availability. Learn more about how it works here: https://youtu.be/mgplcrJh0K0?si=YNz0IVSiN-3myb08
import SwiftUI
extension View {
/// Applies the given transform or returns the untransformed view.
///
/// Useful for availability branching on view modifiers. Do not branch with any properties that may change during runtime as this will cause errors.
/// - Parameters:
/// - transform: The transform to apply to the source `View`.
/// - Returns: The view transformed by the transform.
@ViewBuilder
import SwiftUI
struct WaveformAnimation: View {
@State var waveformData: [CGFloat] = Array(repeating: 0, count: 40)
@State var startAnimation: Bool = false
@State var color: Color = Color(hex: "A28497")
var body: some View {
HStack(spacing: 4) {
ForEach(Array(waveformData.enumerated()), id: \.offset) { index, height in
@sophiateutschler
sophiateutschler / SmoothShadowModifier.swift
Created October 13, 2024 19:44
A SwiftUI view modifier to generate layered/smooth shadows
//
// MIT License
//
// Copyright (c) 2024 Sophiestication Software, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
//
// OCXML.swift
// Created by Marco Arment on 9/23/24.
//
// Released into the public domain. Do whatever you'd like with this.
// No guarantees that it'll do anything, or do it correctly. Good luck!
//
import Foundation
extension StringProtocol {
/// str[NSRange(location:0, length: 9)]
subscript(_ range: NSRange) -> SubSequence {
guard let stringRange = Range<String.Index>(range, in: self) else {
fatalError("String index is out of range")
}
return self[stringRange]
}
@schwa
schwa / XForms.swift
Created June 12, 2024 06:18
XForms.swift
import SwiftUI
struct XForm <Content>: View where Content: View {
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
@chockenberry
chockenberry / ContentView.swift
Created April 18, 2024 21:21
Observable with backing store
//
// ContentView.swift
// ObservableTester
//
// Created by Craig Hockenberry on 4/18/24.
//
import SwiftUI
class BackingStore {
@schwa
schwa / ScreenSaver.swift
Created March 20, 2024 19:52
Silly Swift Screen Saver Sample Source
import SwiftUI
struct Point {
var position: CGPoint
var velocity: CGPoint
}
struct ContentView: View {
@State
var lines: [[Point]] = []
@ppeelen
ppeelen / String+Sanitiser.swift
Last active December 11, 2023 07:43
A simple sanitiser for Swift strings. Removed certain sensitive information; great for using in logs.
extension String {
/**
Sanitizes the string by obscuring sensitive information.
- Returns: A sanitized version of the string where sensitive information is replaced with `*******`.
This method searches for specific keys (namely `access_token`, `refresh_token`, and `id_token`) in various formats including JSON-like strings, query strings, HTTP headers, plain text, and also searches for email addresses. It replaces their associated values or the email addresses with a placeholder string to obscure sensitive information.
## Examples:
@levelsio
levelsio / gist:5bc87fd1b1ffbf4a705047bebd9b4790
Last active March 5, 2025 02:34
Secret of Monkey Island: Amsterdam (by @levelsio) or how to create your own ChatGPT image+text-based adventure game
# 2023-11-27 MIT LICENSE
Here's the open source version of my ChatGPT game MonkeyIslandAmsterdam.com.
It's an unofficial image+text-based adventure game edition of Monkey Island in Amsterdam, my home town.
Please use it however you want. It'd be nice to see more ChatGPT-based games appear from this. If you get inspired by it, please link back to my X https://x.com/levelsio or this Gist so more people can do the same!
Send me your ChatGPT text adventure game on X, I'd love to try it!