Skip to content

Instantly share code, notes, and snippets.

View jverkoey's full-sized avatar

Jeff Verkoeyen jverkoey

View GitHub Profile
@jverkoey
jverkoey / App.swift
Created March 9, 2026 02:28
Reproduction case for stale .swiftmodule files in swift-build (swbuild) - https://github.com/swiftlang/swift-build/issues/1171
import Foundation
#if canImport(MiddleLib)
import MiddleLib
#endif
public struct AppGreeting: Sendable {
#if canImport(MiddleLib)
public static let message = MiddleHelper.name
#else
@jverkoey
jverkoey / rubberBand.swift
Created November 30, 2016 06:55
Rubber banding in swift
public func rubberBand(value: CGFloat, min: CGFloat, max: CGFloat, bandLength: CGFloat) -> CGFloat {
if value >= min && value <= max {
// While we're within range we don't rubber band the value.
return value
}
if bandLength <= 0 {
// The rubber band doesn't exist, return the minimum value so that we stay put.
return min
@jverkoey
jverkoey / SpotifyDrilldown.swift
Created July 31, 2024 15:05
Spotify drilldown filter
import SwiftUI
struct SpotifyToggle: View {
let value: String
@Binding var selection: String?
let didTap: () -> Void
var body: some View {
Toggle(value, isOn: .init(get: { selection == value }, set: { _ in
withAnimation {
if selection == nil {
@jverkoey
jverkoey / SeamlessCarousel.swift
Last active August 6, 2024 17:17
Threads: seamless carousel in SwiftUI
import SwiftUI
struct SeamlessCarouselDemo: View {
@State private var seamless = false
@ViewBuilder
func image(_ name: String) -> some View {
Image(name)
.resizable(resizingMode: .stretch)
.aspectRatio(contentMode: .fit)
@jverkoey
jverkoey / StockGraph.swift
Created August 5, 2024 13:25
Stock graph
import Charts
import SwiftUI
let oneDay: TimeInterval = 60 * 60 * 24
struct ContentView: View {
var body: some View {
let history = loadHistory()
.filter { $0.id > Date.now.addingTimeInterval(-oneDay * 30) }
let analysis = TradingAnalysis(history: history)
@jverkoey
jverkoey / FlipButton.swift
Last active August 1, 2024 12:49
Google Maps directions button
import SwiftUI
struct FlipButton: View {
@State private var orientation: Int = 0
var body: some View {
Button {
orientation += 180
} label: {
Image(systemName: "arrow.up.arrow.down")
@jverkoey
jverkoey / LinkedInActivityIndicator.swift
Last active July 30, 2024 11:53
LinkedIn activity indicator in SwiftUI
import SwiftUI
struct LinkedInActivityIndicator: View {
@State private var animating = false
let cornerRadius: CGFloat
var body: some View {
GeometryReader { proxy in
ZStack {
@jverkoey
jverkoey / Figma analytics API.md
Last active March 29, 2024 18:49
Figma's undocumented analytics API endpoints

Notice

This is an undocumented API. It may break at any time. Contributions welcome; please share in the comments and I will update the gist accordingly.

Authentication

Each request must be passed a valid authentication cookie. The cookie takes the following form and can be pulled from any authenticated request made in the browser:

@jverkoey
jverkoey / underdampedoscillations.m
Last active September 11, 2022 18:53
Underdamped Harmonic Oscillations
// NOTE: I've decided to use a much simpler approach to this as the complexity was starting to consume
// too much energy. Leaving this here for historical context.
// Building an Underdamped Harmonic Oscillator
//
// All equations derived from this wonderful paper by David Morin:
// http://www.people.fas.harvard.edu/~djmorin/waves/oscillations.pdf
//
// Note on mass: In order to simplify our calculations I'll assume that mass (m) is always 1. Where
// m would otherwise be written I've folded it into the expression.
@jverkoey
jverkoey / ios7springs.m
Created April 9, 2014 13:59
iOS 7 spring damping and stiffness calculation
@interface NSObject ()
- (void)generateSpringPropertiesForDuration:(float)arg1 damping:(float)arg2 velocity:(float)arg3;
- (id)_defaultAnimationForKey:(id)arg1;
@end
// This object calculates the damping and stiffness coefficients, given a damping value (0...1], a velocity, and a duration.
id obj = [[NSClassFromString(@"UIViewSpringAnimationState") alloc] init];
[obj generateSpringPropertiesForDuration:10 damping:0.5 velocity:10];