Skip to content

Instantly share code, notes, and snippets.

💭
🏔🏃‍♂

Rui Peres RuiAAPeres

💭
🏔🏃‍♂
Block or report user

Report or block RuiAAPeres

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@RuiAAPeres
RuiAAPeres / opaqueEquivalent.swift
Last active Feb 18, 2020
Extension to provide an equivalent opaque UIColor to a UIColor with alpha channel. So: f(r,g,b,a) == (r,g,b,1)
View opaqueEquivalent.swift
import UIKit
public extension UIColor {
var components: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
View navigation+modal.swift
//
// ContentView.swift
// navigation
//
// Created by Thomas Ricouard on 13/10/2019.
// Copyright © 2019 Thomas Ricouard. All rights reserved.
//
import SwiftUI
View animationcurves.swift
//
// ContentView.swift
// AnimationTimingCurve
//
// Created by Chris Eidhof on 25.09.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
@RuiAAPeres
RuiAAPeres / covariance_contravariance.swift
Last active Sep 16, 2019
Covariance and Contravariance in Swift
View covariance_contravariance.swift
import UIKit
// Based on https://www.stephanboyer.com/post/132/what-are-covariance-and-contravariance
// > Denotes "a subtype of"
// UIButton > UIView > UIResponder > NSObject
//
// e.g. `UIButton` is a subtype of `UIView`
//
// This means that any function that takes a `UIView`, can receive a `UIButton`:
//
@JaviSoto
JaviSoto / NibInstantiable.swift
Last active Sep 1, 2016
RSwift Fabric Extensions
View NibInstantiable.swift
import UIKit
import Rswift
struct NibResource: NibResourceType {
let name: String
let bundle: NSBundle
init(name: String, bundle: NSBundle = NSBundle.mainBundle()) {
self.name = name
self.bundle = bundle
View Signal+Extensions.swift
//
// Signal+Extensions.swift
// Khan Academy
//
// Created by Nacho Soto on 10/1/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import ReactiveCocoa
@JadenGeller
JadenGeller / List Comprehension.swift
Last active Mar 17, 2018
Nondeterministic Computation with Arrays
View List Comprehension.swift
// In languages like Python and Haskell, we can write list comprehension syntax like
// super simply to generate complex lists. Below, for example, we find all numbers that are
// the product of two sides of a triangle.
// [a * b | a <- [1..10], b <- [1..10], c <- [1..10], a * a + b * b == c * c]
// Why is this called nondeterministic computation? Because we essentially try ALL possible combinations
// of these values (a,b) and--you can imagine--run them all simultanously and get the result that matches the predicate.
// Now, obviously, this doesn't all happen at the same time, but that's the idea behind the nondeterminism.
// Let's examine how we can get a similiar result in Swift! We'll start super simple and work
View repmin.swift
// This accompanies http://chris.eidhof.nl/posts/repmin-in-swift.html
import UIKit
// Unfortunately, we need Box
public class Box<T> {
public let unbox: T
public init(_ value: T) { self.unbox = value }
}
@kongtomorrow
kongtomorrow / gist:e153a95907d188fb078a
Created Jun 10, 2014
@auto_closure for control over evaluation
View gist:e153a95907d188fb078a
func myAnd(lhs : Bool, rhs : @auto_closure () -> Bool) -> Bool {
if lhs {
return rhs()
} else {
return false
}
}
func logAndBool(val : Bool) -> Bool {
println("evaluating and returning \(val)!")
You can’t perform that action at this time.