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
#!/usr/bin/ruby | |
require 'json' | |
require 'set' | |
if ARGV.count != 3 | |
abort <<~eos | |
\e[31m⛔️ Provide arguments: | |
1) Path to Pods directory | |
2) Path to pod parent directory | |
3) Pod name\e[0m |
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
extension Set { | |
/// Inserts other collection to current. It works like the `insert` method, but not like the `union`. | |
func inserts<S: Sequence>(_ other: S) -> Self where S.Element == Element { | |
var new = self | |
other.forEach { new.insert($0) } | |
return new | |
} | |
} |
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
protocol OptionalType { | |
associatedtype Wrapped | |
var optional: Wrapped? { get } | |
} | |
extension Optional: OptionalType { | |
var optional: Self { self } | |
} | |
extension Optional { |
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
final class Storage { | |
init() { print(“Storage init.”) } | |
} | |
final class Example { | |
@LazyOnce var storage = Storage() | |
} | |
let example = Example() // Output: | |
example.storage // Output: Storage init. |
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
@propertyWrapper final class LazyOnce<T> { | |
var wrappedValue: T { | |
if let existStorage = storage { return existStorage } | |
let newStorage = lazyBlock() | |
self.storage = newStorage | |
return newStorage | |
} | |
private var storage: T? | |
private let lazyBlock: () -> T | |
init(wrappedValue: @escaping @autoclosure () -> 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
@propertyWrapper | |
final class LazyOnce<T> { | |
private var storage: T? | |
private let lazyBlock: () -> T | |
var wrappedValue: T { | |
if let existStorage = storage { return existStorage } | |
let newStorage = lazyBlock() | |
self.storage = newStorage | |
return newStorage |
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
#!/usr/bin/ruby | |
require 'set' | |
# Constants | |
OUTPUT_BULLET = "•" | |
OUTPUT_BULLET_COLORS = [9, 3, 2, 75, 99] | |
# Help information | |
HELP_COMMANDS = ["-h", "--help", "help"] |
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
#------------------------------------------------------------------------------- | |
# CocoaPods | |
#------------------------------------------------------------------------------- | |
function pods_install() { | |
red="\001$(tput setaf 1)\002" | |
yellow="\001$(tput setaf 3)\002" | |
green="\001$(tput setaf 2)\002" | |
reset="\001$(tput sgr0)\002" | |
if [ "$1" = "-f" ] ; then |
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
struct WithoutEscapingSlashesEncoder { | |
private enum EncoderError: InternalError { | |
case dataToUTF8 | |
case utf8ToData | |
} | |
func encode<T: Encodable>(_ object: T) throws -> Data { | |
let jsonEncoder = JSONEncoder() | |
if #available(iOS 13, *) { |