Skip to content

Instantly share code, notes, and snippets.

View m1guelpf's full-sized avatar

Miguel Piedrafita m1guelpf

View GitHub Profile
@jsmmth
jsmmth / ContentView.swift
Last active July 26, 2025 18:59
SwiftUI Animated Dashed Border
import SwiftUI
struct AnimatedBorder: View {
@State private var phase: CGFloat = 0
let cornerRadius: CGFloat = 25
let dashPattern: [CGFloat] = [15, 15]
let lineWidth: CGFloat = 4
var body: some View {
ZStack {
@jsmmth
jsmmth / Swift UI StarField Experiment
Created July 13, 2025 15:46
Pretty messy, probably quite un-optimised fun SwiftUI star field experiment.
import SwiftUI
import MetalKit
import simd
// MARK: - Metal View
struct MetalStarfieldView: UIViewRepresentable {
@Binding var speed: Double
@Binding var cameraShake: CGSize
let hyperdriveCallback: () -> Void
@samhenrigold
samhenrigold / q&a.md
Created June 11, 2025 02:07
WWDC25 Camera/Photos Group Lab Q&A

What’s the first class way to use PhotoKit to reimplement a high performance photo grid? We’ve been using a LazyVGrid and the photos caching manager, but are never able to hit the holy trinity (60hz, efficient memory footprint, minimal flashes of placeholder/empty cells)

A few things. It sounds like you're using the PHCachingImageManager already, which is definitely recommended.

One kind of specific note there—you want to use that to get media content delivered before you need to display it. So, for example, let's say you're showing a large grid of photos. You can be prefetching before and after, in expectation that the user's going to scroll. Or, if you're in a one-up situation, prefetching left and right so that you know the user is likely going to swipe, and you can quickly deliver those images to the screen and cache them.

Another thing you should really make sure you're doing is specifying the size you need for the grid size. For example, if your app supports showing a smaller grid

import UIKit
import CoreImage
public extension UIImage {
/// Draws a rounded, solid‐color outline around this image’s alpha shape,
/// then composites the full-color image back in the center.
///
/// - Parameters:
/// - strokeColor: the color of the ring
/// - strokeWidth: the thickness of the ring (in points)
@hanxiao
hanxiao / testRegex.js
Last active August 18, 2025 11:19
Regex for chunking by using all semantic cues
// Updated: Aug. 20, 2024
// Run: node testRegex.js whatever.txt
// Live demo: https://jina.ai/tokenizer
// LICENSE: Apache-2.0 (https://www.apache.org/licenses/LICENSE-2.0)
// COPYRIGHT: Jina AI
const fs = require('fs');
const util = require('util');
// Define variables for magic numbers
const MAX_HEADING_LENGTH = 7;
@xlr8harder
xlr8harder / sydney.py
Created August 2, 2024 18:49
Talk to Sydney with Llama 3.1 405B base model.
import gradio as gr
from openai import OpenAI
import jinja2
from transformers import AutoTokenizer
# get an api key from hyperbolic.
api_key = "..."
# Initialize the OpenAI client
client = OpenAI(
@drewolbrich
drewolbrich / InputNotWorkingIndicator.swift
Last active August 11, 2024 03:33
A recreation of the Mac Virtual Display "Input temporarily not working" indicator
//
// InputNotWorkingIndicator.swift
//
// Created by Drew Olbrich on 6/26/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
import SwiftUI
// Remember to download FontSettings.swift
struct WWDC24AnimatedTextView: View {
var text = "Hello, World!"
var animation: Animation = .easeInOut
var targetFontSize: CGFloat = 40
var minimumFontSize: CGFloat = 30
var targetFontWeight: Font.Weight = .semibold
@davidsteppenbeck
davidsteppenbeck / AnimatingMeshView.swift
Created June 11, 2024 16:41
Animating mesh gradient for iOS 18 using TimelineView
import SwiftUI
struct AnimatingMeshView: View {
let referenceDate: Date
var body: some View {
TimelineView(.animation) { context in
let t = context.date.timeIntervalSince(referenceDate)
MeshGradient(width: 5, height: 4, points: [
@JamesSedlacek
JamesSedlacek / KeyboardToolbar.swift
Last active July 1, 2025 11:52
SwiftUI Keyboard Toolbar Workaround
//
// KeyboardToolbar.swift
//
// Created by James Sedlacek on 9/20/23.
//
import SwiftUI
import Combine
@Observable