Skip to content

Instantly share code, notes, and snippets.

View NSStudent's full-sized avatar
🏠
Working from home

Omar NSStudent

🏠
Working from home
View GitHub Profile
@radiofun
radiofun / simplewavenoise.metal
Last active March 21, 2026 05:06
Simple Wave with Noise
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
float hash21(float2 p) {
float3 p3 = fract(float3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
@radiofun
radiofun / SiriAnimation.metal
Created February 15, 2026 19:55
Siri Animation
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
float sdBox(float2 p, float2 b) {
float2 q = abs(p) - b;
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0));
}
float sdRoundBox(float2 p, float2 b, float radius) {
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
[[ stitchable ]] half4 simpledistort(float2 pos, SwiftUI::Layer l, float4 boundingRect, float progress, float distortion) {
float2 size = boundingRect.zw;
float2 uv = pos / size;
float2 center = float2(0.5, 0.5);
float2 delta = uv - center;
@radiofun
radiofun / DistortionTransition.metal
Created January 4, 2026 17:20
DistortionTransition.metal
[[ stitchable ]] half4 distortionWithScale(float2 pos, SwiftUI::Layer l, float4 boundingRect, float2 dragp, float progress) {
float2 delta = pos - dragp;
float dist = length(delta);
// Define the influence of the "force" from the drag point
float radius = 155.0; // Radius of effect
float strength = 0.8; // How much it pulls
// Influence peaks at 0.5, is 0 at 0.3 and 1.0 - you can customize these values.
float progressinfluence = smoothstep(0.3, 0.5, progress) * (1.0 - smoothstep(0.5, 1.0, progress));
@radiofun
radiofun / Distortion.metal
Created January 1, 2026 22:14
Distortion Shader that is influenced by dragging position.
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
//Use DistortionSampleView.swift to try it out
//2026 Minsang Choi
[[ stitchable ]] half4 distortion(float2 pos, SwiftUI::Layer l, float4 boundingRect, float2 dragp) {
float2 delta = pos - dragp;
@IanKeen
IanKeen / Abstraction.swift
Created August 16, 2022 17:41
TCA Scoping Abstraction
// MARK: - TCAView
public protocol TCAView: View where Body == WithViewStore<ScopedState, ScopedAction, Content> {
associatedtype ViewState
associatedtype ViewAction
associatedtype ScopedState
associatedtype ScopedAction
associatedtype Content
@nikitamounier
nikitamounier / PredicateSet.swift
Created October 25, 2021 10:18
A simple PredicateSet type, with only one property of type (Element) -> Bool, which (nearly) conforms to SetAlgebra.
struct PredicateSet<Element: Equatable> {
var contains: (Element) -> Bool
init(_ contains: @escaping (Element) -> Bool) {
self.contains = contains
}
}
extension PredicateSet: SetAlgebra {
init() {
@tanner0101
tanner0101 / vapor-4-fluent-authc.swift
Last active May 2, 2024 14:24
Example of authentication with Fluent in Vapor 4
import Fluent
import Vapor
func routes(_ app: Application) throws {
app.post("users") { req -> EventLoopFuture<User> in
try User.Create.validate(req)
let create = try req.content.decode(User.Create.self)
guard create.password == create.confirmPassword else {
throw Abort(.badRequest, reason: "Passwords did not match")
}
//
// Diagrams.swift
// DiagramsSample
//
// Created by Chris Eidhof on 16.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
@chriseidhof
chriseidhof / viewmirror.swift
Last active December 18, 2025 12:17
View Mirror
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Text("Hello")
.padding()
.background(.blue)
.overlay {
Color.yellow