Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@el-hoshino
el-hoshino / AssociativeComparisonPrecedence.swift
Last active February 5, 2024 22:40
AssociativeComparison
precedencegroup AssociativeComparisonPrecedence {
associativity: left
higherThan: ComparisonPrecedence
lowerThan: NilCoalescingPrecedence
}
infix operator <: AssociativeComparisonPrecedence
infix operator <=: AssociativeComparisonPrecedence
public func < <V: Comparable>(lhs: V, rhs: V) -> (Bool, V) {
@bellbind
bellbind / bezier-interpolation.js
Last active April 15, 2020 07:06
[browser] Bezier(3-degree Spline) Interpolation 2D
// make equation coefficients and vectors of x and y for bezier interpolation
export function bezierControlsEquation(knots) {
// [Theory of Beizer Interpolation]
// bezier curve:
// - p(t) = (1-t)^3*P0 + 3(1-t)^2*t*C0 + 3(1-t)t^2*C1 + t^3*P1
// - p(0) = P0
// - p(1) = P1
// - p'(t) = -3(t^2-2t+1)*P0 + 3(3t^2-4t+1)*C0 + 3(-3t^2+2t)*C1 + 3t^2*P1
// - p'(0) = -3*P0 + 3*C0
// - p'(1) = -3*C1 + 3*P1
@fmtonakai
fmtonakai / AttributedString.swift
Last active August 6, 2023 21:27
AttributedString with String Interpolation
//
// AttributedString.swift
//
// Created by fm.tonakai on 2019/04/08.
//
import UIKit
public struct AttributedString: ExpressibleByStringLiteral, ExpressibleByStringInterpolation, CustomStringConvertible {
public struct StringInterpolation: StringInterpolationProtocol {
@algal
algal / Zipping.swift
Created February 17, 2019 01:18
Zip files on iOS, without using external libraries and without interoperating with the low-level Compression framework
// Zipping.swift
// known-good: Swift 4.2
// Alexis Gallagher
import Foundation
public extension URL {
/// Creates a zip archive of the file or folder represented by this URL and returns a references to the zipped file
///
@simonseyer
simonseyer / WeakSet.swift
Created February 27, 2018 15:37
Typesafe implementation of a weak set in Swift 4
import Foundation
public class WeakSet<T: AnyObject>: Sequence, ExpressibleByArrayLiteral, CustomStringConvertible, CustomDebugStringConvertible {
private var objects = NSHashTable<T>.weakObjects()
public init(_ objects: [T]) {
for object in objects {
insert(object)
}
@hooman
hooman / RationalNumber.swift
Last active January 26, 2021 15:40
Rational numbers in Swift 3.0
// RationalNumber.swift
//
// A basic implementation of Rational numbers in Swift 3.0.
// (c) 2016 Hooman Mehr. Licensed under Apache License v2.0 with Runtime Library Exception
/// A data type to model rational numbers in Swift.
///
/// It always uses fully-reduced representation for simplicity and clarity of comparisons and uses LCM
@FredrikSjoberg
FredrikSjoberg / RGBtoHSV.swift
Last active April 11, 2024 11:22
Color space conversion between RGB and HSV
// https://www.cs.rit.edu/~ncs/color/t_convert.html
struct RGB {
// Percent
let r: Float // [0,1]
let g: Float // [0,1]
let b: Float // [0,1]
static func hsv(r: Float, g: Float, b: Float) -> HSV {
let min = r < g ? (r < b ? r : b) : (g < b ? g : b)
let max = r > g ? (r > b ? r : b) : (g > b ? g : b)
#import "UIResponder+FirstResponder.h"
static __weak id currentFirstResponder;
@implementation UIResponder (FirstResponder)
+ (id)currentFirstResponder
{
currentFirstResponder = nil;
[[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil];
@cromandini
cromandini / universal-framework.sh
Last active February 12, 2024 12:13 — forked from cconway25/gist:7ff167c6f98da33c5352
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures).
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build