Skip to content

Instantly share code, notes, and snippets.

🚜
Working

StanislavK StanislavK

🚜
Working
Block or report user

Report or block StanislavK

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
View gist:9233c7f229f58fc10d03f9518dd5e3d4
#Use this when you need to have working playground and project: see more at https://www.twilio.com/blog/intro-to-markov-models-with-swift
View UIFont+Extensions.swift
extension UIFont {
class func printAllFonts() {
UIFont.familyNames().forEach { family in
UIFont.fontNamesForFamilyName(family).forEach { font in
print(font)
}
}
}
View IsConnected.swift
// Simple check if connected to internet
func isConnected() -> Bool {
// we need SCNetworkReachability object
guard let reachability = SCNetworkReachabilityCreateWithName(nil, "https://inloop-contacts.appspot.com/_ah/api/contactendpoint/v1/contact") else { return false }
// and flags
var flags = SCNetworkReachabilityFlags()
// read the "flags" into flags (via SCNetworkReachabilityGetFlags)
SCNetworkReachabilityGetFlags(reachability, &flags)
View Foo.swift
class SharePromptView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
createSubviews()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
createSubviews()
}
func createSubviews() {
View UIViewController+Extensions.swift
// That’s marked @nonobjc so it won’t conflict with any of Apple’s own code, now or in the future.
@nonobjc extension UIViewController {
func add(_ child: UIViewController, frame: CGRect? = nil) {
addChildViewController(child)
if let frame = frame {
child.view.frame = frame
}
view.addSubview(child.view)
child.didMove(toParentViewController: self)
}
View Foo.swift
extension UIView {
func add(_ subviews: UIView...) {
subviews.forEach(addSubview)
}
}
view.add(button)
view.add(label)
// By dropping the "Subview" suffix from the method name, both
View Codable+Extensions.swift
extension Encodable {
func encode(with encoder: JSONEncoder = JSONEncoder()) throws -> Data {
return try encoder.encode(self)
}
}
extension Decodable {
static func decode(with decoder: JSONDecoder = JSONDecoder(), from data: Data) throws -> Self {
return try decoder.decode(Self.self, from: data)
}
@StanislavK
StanislavK / Foo.txt
Last active Feb 23, 2018
Make TODO: + FIXME: + WARNING: as warnings, ERROR: as error
View Foo.txt
TAGS="TODO:|FIXME:|WARNING:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"| perl -p -e "s/($ERRORTAG)/ error: \$1/"
View ImagePainter.swift
import UIKit
import CoreImage
class ImagePainter {
let context = CIContext(options:[kCIImageColorSpace: NSNull()])
let filter = CIFilter(name: "CIFalseColor",
withInputParameters: ["inputColor1" : CIColor(color: .black)])
View UIView+Extensions.swift
import UIKit
extension UIView {
func pinEdgesToSafeArea(of view: UIView) {
self.translatesAutoresizingMaskIntoConstraints = false
self.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
self.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
self.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
self.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
}
You can’t perform that action at this time.