Skip to content

Instantly share code, notes, and snippets.

View StevenMasini's full-sized avatar
🐒
Climbing trees and eating bananas 🍌

Steven Masini StevenMasini

🐒
Climbing trees and eating bananas 🍌
View GitHub Profile
@StevenMasini
StevenMasini / Permutation.swift
Last active July 8, 2017 16:24
My implementation of the Permutation algorithm in Swift
class Permutator {
class func permutation(_ str: String) -> Set<String> {
return permutation(str, prefix: "")
}
private class func permutation(_ str: String, prefix: String) -> Set<String> {
if str.characters.count == 0 {
return [prefix]
}
@StevenMasini
StevenMasini / Quicksort.swift
Last active June 15, 2017 11:59
My implementation of the Quicksort algorithm in Swift
func quicksort<T: Comparable>(_ arr: [T]) -> [T] {
guard arr.count > 1 else {
return arr
}
let pivot = arr[arr.count / 2]
var left = [T]()
var equal = [T]()
var right = [T]()
@StevenMasini
StevenMasini / Log.swift
Last active December 3, 2017 08:39
Unconventional logger
import Foundation
public struct Log {
fileprivate enum Tag: String {
case verbose = "🔷"
case success = "✅"
case warning = "⚠️"
case error = "🚫"
case json = "📦"
}
extension UIColor {
/// Init a UIColor base on the color hexadecimal value
///
/// - Parameters:
/// - hex: Hexadecimal code of the color
/// - alpha: Alpha opacity, between 0 and 1
public convenience init(hex: UInt, alpha: CGFloat) {
self.init(
red: CGFloat((hex & 0xFF0000) >> 16) / 255.0,
green: CGFloat((hex & 0x00FF00) >> 8) / 255.0,
extension UIView {
/// Load a view from a nib file and return it.
/// The Class and the Nib file must have the same name.
/// The nib file should contain only one view.
///
/// - Returns: The first view found in the nib file.
static func loadInstanceFromNib<T: UIView>() -> T? {
return Bundle.main.loadNibNamed(String(describing: classForCoder()), owner: self, options: nil)?[0] as? T
}
}
@StevenMasini
StevenMasini / RandomDate.swift
Created April 23, 2020 15:48
Create random Date
import Foundation
func generateRandomDate(daysBack: Int)-> Date?{
let day = arc4random_uniform(UInt32(daysBack))+1
let hour = arc4random_uniform(23)
let minute = arc4random_uniform(59)
let today = Date(timeIntervalSinceNow: 0)
let gregorian = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)
var offsetComponents = DateComponents()
@StevenMasini
StevenMasini / ContentViewModel.swift
Created August 23, 2021 06:35
Multi Nearby Interaction
import Foundation
import NearbyInteraction
import MultipeerConnectivity
import Combine
var numberFormatter: NumberFormatter {
let numberFormatter = NumberFormatter()
numberFormatter.roundingMode = .halfEven
numberFormatter.maximumFractionDigits = 3
numberFormatter.minimumFractionDigits = 3