Skip to content

Instantly share code, notes, and snippets.

@jasdev
jasdev / ScrimLoader.swift
Last active March 30, 2023 09:21
Rough sketch of Arc’s scrim loading view.
View ScrimLoader.swift
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`.
View Wallet.swift
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 October 11, 2022 08:13
Decode and Flatten JSON with Dynamic Keys Using Swift Decodable (https://swiftsenpai.com/swift/decode-dynamic-keys-json/)
View Decode-Dynamic-Keys-JSON-Final.swift
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
View iOSCustomSegmentedControlSwiftUI.swift
import SwiftUI
extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
@mecid
mecid / PagerView.swift
Last active December 25, 2022 00:51
PagerView in SwiftUI
View PagerView.swift
//
// 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
View InterpolationAlgorithm.swift
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 December 1, 2022 10:15
Combine - fetching and decoding JSON data
View CombineFetcherAndDecoder.swift
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
View mastodon-tootctl-media-purge.txt
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.
View DynamicKey.swift
/**
```
// 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 {
@uqmessias
uqmessias / devices-model-resolution.md
Last active February 15, 2023 17:39
Some Android devices dimensions
View devices-model-resolution.md