Skip to content

Instantly share code, notes, and snippets.

@dkun7944
dkun7944 / ContentView.swift
Created July 31, 2023 03:36
AirDrop iOS 17 Swift.Shader Animation
//
// ContentView.swift
// Airdrop Demo
//
// Created by Daniel Kuntz on 7/30/23.
//
import SwiftUI
struct ContentView: View {
@jasdev
jasdev / ScrimLoader.swift
Last active April 19, 2024 03:47
Rough sketch of Arc’s scrim loading view.
import SwiftUI
/**
### Exercises for the viewer
- Phase interrupt handling.
- Use Swift concurrency.
- Color scheme awareness.
- Rework animations to be more spring-like à la what shipped in `0.90.0`.
import SwiftUI
import PlaygroundSupport
// constants
let cardWidth: CGFloat = 343
let cardHeight: CGFloat = 212
let spacing = 36
let animation = Animation.spring()
let cardColors = [
Color(UIColor.systemRed),
@LeeKahSeng
LeeKahSeng / Decode-Dynamic-Keys-JSON-Final.swift
Last active June 4, 2023 14:04
Decode and Flatten JSON with Dynamic Keys Using Swift Decodable (https://swiftsenpai.com/swift/decode-dynamic-keys-json/)
import Foundation
let jsonString = """
{
"S001": {
"firstName": "Tony",
"lastName": "Stark"
},
"S002": {
"firstName": "Peter",
@frankfka
frankfka / iOSCustomSegmentedControlSwiftUI.swift
Created May 17, 2020 16:47
Custom Segmented Picker / Segmented Control in SwiftUI
import SwiftUI
extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
@mecid
mecid / PagerView.swift
Last active December 10, 2023 19:24
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
@castillejoale
castillejoale / InterpolationAlgorithm.swift
Last active April 24, 2022 22:46
Swift - interpolation function
import simd
static func interpolate(desiredX: inout [Float], y: inout [Float]) -> [Float] {
let n = desiredX.count - 1
let stride = vDSP_Stride(1) //Int Type Alias
let denominator = Float(n) / Float(y.count - 1)
let control: [Float] = desiredX.map {
let x = Float($0) / denominator
let smoothStep = Float(simd_smoothstep(0, 1, simd_fract(x)))
@stinger
stinger / CombineFetcherAndDecoder.swift
Last active February 17, 2024 02:07
Combine - fetching and decoding JSON data
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String), parserError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"
@ThomasLeister
ThomasLeister / mastodon-tootctl-media-purge.txt
Created February 21, 2019 19:07
How to automatically remove cached media files older that 7 days from your Mastodon instance
This is how to automatically delete cached image previews from your Mastodon instance if they are older than 7 days.
Log in as your "mastodon" User or log in as root and then change to the "mastodon" user, who runs Mastodon:
# su - mastodon
Open crontab:
$ crontab -e
... and add these lines to your crontab:
@samwize
samwize / DynamicKey.swift
Created September 28, 2017 06:59
A CodingKey that is dynamic -- it can be any string! Encode/decode with a Dictionary of `[String : Any]` in the model.
/**
```
// Encode a model with properties of type [String : Any]
var propertiesContainer = container.nestedContainer(keyedBy: DynamicKey.self, forKey: .properties)
if let properties = properties {
try propertiesContainer.encodeDynamicKeyValues(withDictionary: properties)
}
```
*/
struct DynamicKey: CodingKey {