Skip to content

Instantly share code, notes, and snippets.

View warpling's full-sized avatar

Ryan McLeod warpling

View GitHub Profile
@warpling
warpling / BillboardSystem.swift
Last active September 18, 2023 12:57
Billboarding System/Component for RealityKit (you supply headPosition)
import RealityKit
struct BillboardSystem: System {
static let query = EntityQuery(where: .has(BillboardComponent.self))
init(scene: RealityKit.Scene) {}
func update(context: SceneUpdateContext) {
context.scene.performQuery(Self.query).forEach { entity in
@warpling
warpling / UIColor+ContrastChecker.swift
Created September 28, 2020 12:15
Color Extensions
//
// UIColor+ContrastChecker.swift
// Stay Inside
//
// Created by Ryan McLeod on 5/6/20.
// Copyright © 2020 Grow Pixel. All rights reserved.
//
import UIKit
@warpling
warpling / CAMediaTimingFunction.swift
Last active June 14, 2022 11:15
Better CAMediaTimingFunctions
//
// CAMediaTimingFunction.swift
import UIKit
extension CAMediaTimingFunction {
static let linear = CAMediaTimingFunction(name: .linear)
static let easeOut = CAMediaTimingFunction(name: .easeOut)
@warpling
warpling / UIBezierPath+AttributedString.swift
Last active January 10, 2023 05:22
AttributedString to UIBezierPath
extension UIBezierPath {
// Source: https://github.com/aderussell/string-to-CGPathRef/blob/0bd9350dc2100029f3ddb8d9667384841549ecd6/ARCGPathFromString/ARCGPathFromString.m
convenience init(attributedString: NSAttributedString) {
let letters = CGMutablePath()
let line = CTLineCreateWithAttributedString(attributedString as CFAttributedString)
let runArray = CTLineGetGlyphRuns(line)
@warpling
warpling / RegexExample
Created December 14, 2019 14:06
Help me create a regex that captures the first quoted string and the second quoted string!
/* This is not important but maybe useful to the regex */
"this.is.a.reverse-dns.thing" = "Blackbox “Stealth” T-Shirt";
/* This is not important but maybe useful to the regex */
"this.is.another.reverse-dns.thing-it.can.have-hyphens" = "I’m a long string.
I also have line breaks and sometimes \"escaped quotation marks\"
📦 Oh and emojis.";
@warpling
warpling / Mento.playground
Last active August 1, 2019 20:11
Copying Tinder's "mentos" button animation (based on tweet: https://twitter.com/warpling/status/930567671015358464?s=20)
//: Playground - noun: a place where people can play
import UIKit
class Mento: UIView {
// The thickness ratio of our mento, 1.0 being a perfect sphere.
let mentoThicknessScale: CGFloat = 0.60
let shape: UIView = {
@warpling
warpling / Moon.h
Last active July 26, 2023 07:16
🌔 Drawing an accurate moon with UIBezierPath
//
// Moon.h
// Blackbox
//
// Created by Ryan McLeod on 12/2/14.
// Copyright (c) 2014 Ryan McLeod. All rights reserved.
//
#import <UIKit/UIKit.h>
@warpling
warpling / CAMediaTimingFunction+Extended.swift
Last active April 12, 2024 10:33
CAMediaTimingFunctions (Swift 4)
//
// CAMediaTimingFunctions+Extended.swift
// Geiger
//
// Created by Ryan McLeod on 1/22/19.
// Copyright © 2019 Grow Pixel. All rights reserved.
//
import UIKit
@warpling
warpling / MathTools.h
Last active July 28, 2017 18:36
MAPRANGE
// Maps one range onto another
// Example: [-50, 100] to [0, 1.0]
// Example: [0.2, 1.0] to [1.0, 0.0]
#define MAPRANGE(x, inputLow, inputHigh, outputLow, outputHigh) ({\
__typeof(x) __x = (x); \
__typeof(inputLow) __inputLow = (inputLow); \
__typeof(inputHigh) __inputHigh = (inputHigh); \
__typeof(outputLow) __outputLow = (outputLow); \
__typeof(outputHigh) __outputHigh = (outputHigh); \
(((__x - __inputLow) / (__inputHigh - __inputLow)) * (__outputHigh - __outputLow)) + __outputLow; \
@warpling
warpling / SharkfoodMuteSwitchDetector.h
Created April 22, 2017 00:00
SharkfoodMuteSwitchDetector
//
// SharkfoodMuteSwitchDetector.h
//
// Created by Moshe Gottlieb on 6/2/13.
// Copyright (c) 2013 Sharkfood. All rights reserved.
//
#import <Foundation/Foundation.h>