Skip to content

Instantly share code, notes, and snippets.

View salabaha's full-sized avatar

Roman Salabay salabaha

View GitHub Profile
@salabaha
salabaha / ShimmerFragment.swift
Created May 14, 2025 16:44
TextKit 2 implementation of shimmer gradient animation
class ShimmerFragment: NSTextLayoutFragment {
/// Phase in -1...+1 indicating center of the narrow gradient band
var phase: CGFloat = 0.5
var gradientRange: NSRange?
override func draw(at point: CGPoint, in context: CGContext) {
// Draw the entire text normally first
super.draw(at: point, in: context)
@salabaha
salabaha / UIViewBuilder.swift
Last active May 14, 2025 16:42
UIViewBuilder syntactic sugar
import UIKit
///
///Declaration
///
protocol UIViewBuilder: AnyObject {}
extension UIViewBuilder where Self: UIView {
init(_ build: ((Self) -> Void)) {
@salabaha
salabaha / DateRange.swift
Created September 7, 2016 12:00 — forked from preble/DateRange.swift
Experimenting with creating a SequenceType for iterating over a range of dates. Blogged here: http://adampreble.net/blog/2014/09/iterating-over-range-of-dates-swift/
import Foundation
func > (left: NSDate, right: NSDate) -> Bool {
return left.compare(right) == .OrderedDescending
}
extension NSCalendar {
func dateRange(startDate startDate: NSDate, endDate: NSDate, stepUnits: NSCalendarUnit, stepValue: Int) -> DateRange {
let dateRange = DateRange(calendar: self, startDate: startDate, endDate: endDate, stepUnits: stepUnits, stepValue: stepValue, multiplier: 0)
return dateRange