Skip to content

Instantly share code, notes, and snippets.

View fredericdupir's full-sized avatar

Frederic D. fredericdupir

View GitHub Profile
@ryanlintott
ryanlintott / NoClipText.swift
Last active October 1, 2024 18:25
Alternative Text view for SwiftUI with an extendable clipping area. This is a fix for certain fonts and characters that have a clipped intrinsic size.
import SwiftUI
import UIKit
struct NoClipText: UIViewRepresentable {
typealias UIViewType = NoClipLabel
let text: String
let font: UIFont
let clipExtension: EdgeSizes
A list of sketch scripts
@kemalenver
kemalenver / CircleNode.swift
Last active September 19, 2021 03:56
An SCNNode that draws a circle of given detail
import Foundation
import SceneKit
class CircleNode: SCNNode {
init(detail: Int = 500) {
super.init()
let elements = self.generateElements(detail: detail)
@KevinGutowski
KevinGutowski / actions.js
Last active April 13, 2021 13:04
Triggering an action in Sketch
// Example
// Thanks to Aby for the idea / inital code nippet
// https://sketchplugins.com/d/201-inserting-a-layer-into-a-document-with-sketch-ux/7
context.document.actionsController().actionForID("MSShowReplaceColorSheetAction").performAction(nil);
// there may be cases where you need to pass in a reference to an object in order for the for the action to work
// here is how you can insert a symbol instance programmatically
// for now let's assume you have a symbol master selected
@myobie
myobie / ExampleSimplePublisher.swift
Last active April 7, 2020 11:33
Make any class a super simple publisher with publish() and complete() functions
class Names: SimplePublisher {
typealias Output = Result<String, Error>
var subscriptions = [SimpleSubscription<Output, Failure>]()
let names = ["Alice", "Bob", "Claris", "Doug"]
shoutName() {
if let name = names.randomElement() {
publish(.success(name))
} else {
assertionFailure("There are def some names in there...")
@lanserxt
lanserxt / LoopedPlayerView.swift
Last active October 25, 2023 16:18
Loop playback with AVQueuePlayer and AVPlayerLooper
final class LoopedVideoPlayerView: UIView {
fileprivate var videoURL: URL?
fileprivate var queuePlayer: AVQueuePlayer?
fileprivate var playerLayer: AVPlayerLayer?
fileprivate var playbackLooper: AVPlayerLooper?
func prepareVideo(_ videoURL: URL) {
let playerItem = AVPlayerItem(url: videoURL)
@shaps80
shaps80 / FontCacheDescriptor+Graphik.swift
Last active March 19, 2024 14:54
Better font loading in iOS with Swift
extension UIFont {
// The `rawValue` MUST match the filename (without extension)
public enum Graphik: String, FontCacheDescriptor {
case regular = "GraphikAltWeb-Regular"
case medium = "GraphikAltWeb-Medium"
case regularItalic = "GraphikAltWeb-RegularItalic"
case mediumItalic = "GraphikAltWeb-MediumItalic"
}
@joncardasis
joncardasis / UIFont+BestFit.swift
Last active May 11, 2023 03:20
Swift Dynamic Font Size for Bounds
extension UIFont {
/**
Will return the best font conforming to the descriptor which will fit in the provided bounds.
*/
static func bestFittingFontSize(for text: String, in bounds: CGRect, fontDescriptor: UIFontDescriptor, additionalAttributes: [NSAttributedStringKey: Any]? = nil) -> CGFloat {
let constrainingDimension = min(bounds.width, bounds.height)
let properBounds = CGRect(origin: .zero, size: bounds.size)
var attributes = additionalAttributes ?? [:]
@proxpero
proxpero / zip3.swift
Created December 28, 2017 18:49
An implementation of zip that creates a sequence of three-item tuples from the combination of three sequences. Much like the standard library's `zip` function for a pair of sequences.
/// Creates a sequence of tuple-3s built out of three underlying sequences.
/// Based on Zip2Seqence from the Swift Standard Library.
/// https://github.com/apple/swift/blob/9361a6b66f6f8351e89c090f604d7e1f42e2a045/stdlib/public/core/Zip.swift
///
/// - Parameters:
/// - sequence1: The first sequence or collection to zip.
/// - sequence2: The second sequence or collection to zip.
/// - sequence3: The third sequence or collection to zip.
/// - Returns: A sequence of tuple triples, where the elements of each triplet are
/// corresponding elements of `sequence1`, `sequence2`, and `sequence3`.
@ha1f
ha1f / CIFilter+Extension.swift
Last active February 20, 2024 08:14
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {