float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol KeyPathListable { | |
var allKeyPaths: [String: PartialKeyPath<Self>] { get } | |
var keyPathsList: [PartialKeyPath<Self>] { get } | |
} | |
extension KeyPathListable { | |
private subscript(checkedMirrorDescendant key: String) -> Any { | |
Mirror(reflecting: self).descendant(key)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PageIndicator.swift | |
// | |
// Created by Oleksandr Glagoliev on 6/24/20. | |
// Copyright © 2020 Oleksandr Glagoliev. All rights reserved. | |
// | |
import SwiftUI | |
// MARK: - Dot Indicator - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
extension XCTestCase { | |
func trackForMemoryLeaks(_ instance: AnyObject, file: StaticString = #filePath, line: UInt = #line) { | |
addTeardownBlock { [weak instance] in | |
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by @fewlinesofcode on 9/6/18. | |
// Copyright (c) 2018 Oleksandr Glagoliev. All rights reserved. | |
// | |
public class Interval<T: Comparable> { | |
private (set) var start: T | |
private (set) var end: T | |
var max: T | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public extension CGPoint { | |
func distance(to point: CGPoint) -> CGFloat { | |
let xDist = x - point.x | |
let yDist = y - point.y | |
return (xDist * xDist + yDist * yDist).squareRoot() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* | |
> Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages. Swift’s closure expressions have a clean, clear style, with optimizations that encourage brief, clutter-free syntax in common scenarios. | |
For better understanding, I strongly recommend you to read the [Swift functions cheatsheet]({% post_url 2016-02-12-swift-functions-cheatsheet %}) and it's sources. | |
# Closure syntax | |
Since any function is the special case of closure, they are pretty the same. Basic difference is the way of writing and the use purpose. Closures syntax is optimized to be convenient for *inlining*, *passing as parameter* and *using as return type* of other functions. | |
The general form of the Swift closure is: | |
{ (parameters) -> ReturnType in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// | |
// CGVectorArithmetics.swift | |
// | |
// Created by fewlinesofcode.com on 2/6/19. | |
// Copyright © 2019 fewlinesofcode.com All rights reserved. | |
// | |
import Foundation | |
import CoreGraphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Vector2D.swift | |
// | |
// Created by fewlinesofcode.com on 2/6/19. | |
// Copyright © 2019 fewlinesofcode.com All rights reserved. | |
// | |
import Foundation | |
struct Vector2D { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The $1 Unistroke Recognizer | |
* | |
* Jacob O. Wobbrock, Ph.D. | |
* The Information School | |
* University of Washington | |
* Seattle, WA 98195-2840 | |
* wobbrock@uw.edu | |
* | |
* Andrew D. Wilson, Ph.D. |
NewerOlder