Skip to content

Instantly share code, notes, and snippets.

View Marcocanc's full-sized avatar
🚀

Marco Cancellieri Marcocanc

🚀
View GitHub Profile
@Marcocanc
Marcocanc / ExternalIntent.swift
Last active January 27, 2017 13:37
External Intent Enum
enum ExternalIntent {
case content(id: String)
case timeline
case example
init?(launchOptions: [UIApplicationLaunchOptionsKey: Any]?) {
guard let launchOptions = launchOptions else { return nil }
if let url = launchOptions[.url] as? URL {
self.init(url: url)
} else if let shortcutItem = launchOptions[.shortcutItem] as? UIApplicationShortcutItem {
@Marcocanc
Marcocanc / UITableView+DeselectAny.swift
Created February 20, 2017 13:41
deselect any UITableViewRow that may be selected
extension UITableView {
//deselect any row that may be selected
public func deselectAnyRow(animated: Bool = true) {
if let indexPath = self.indexPathForSelectedRow {
self.deselectRow(at: indexPath, animated: animated)
}
}
}
@Marcocanc
Marcocanc / JSON+Decimal.swift
Last active April 20, 2017 09:24
JSON+Decimal
import Foundation
import SwiftyJSON
extension JSON {
public var decimal: Decimal? {
get {
switch self.type {
case .string:
return Decimal(string: self.object as! String)
case .number:
@Marcocanc
Marcocanc / UIFont+FontWeight.swift
Created March 8, 2017 16:17
really hoping this will work out of the box in future versions
public extension UIFont {
public class func systemFont(ofSize fontSize: CGFloat, weight: UIFontWeight) -> UIFont {
return .systemFont(ofSize: fontSize, weight: weight.floatValue)
}
public class func monospacedDigitSystemFont(ofSize fontSize: CGFloat, weight: UIFontWeight) -> UIFont {
return .monospacedDigitSystemFont(ofSize: fontSize, weight: weight.floatValue)
}
}
@Marcocanc
Marcocanc / UINavigationItem+Reactive.swift
Last active April 5, 2017 08:50
UINavigationItem+Reactive.swift
//
// UINavigationItem+Reactive.swift
// ReactiveQuotes
//
// Created by Marco Cancellieri on 14/01/2017.
// Copyright © 2017 Marco Cancellieri. All rights reserved.
//
import UIKit
import ReactiveSwift
extension Collection {
public subscript(safe index: Index) -> Optional<Iterator.Element> {
guard self.startIndex..<self.endIndex ~= index else { return nil }
return self[index]
}
}
@Marcocanc
Marcocanc / scw-rclone-sync.sh
Last active December 31, 2021 11:48
Create a scaleway instance, put rclone and its config on it, sync drives and then terminate the the server
#!/bin/bash
set -e
SCALEWAY='scw --region="ams1"'
ARCH=X64
COMM_TYPE=$ARCH-2GB
IMAGE=xenial
TRANSFERS=7
TG_TOKEN=<BOT_TOKEN>
@Marcocanc
Marcocanc / FontWeight.swift
Last active June 15, 2017 12:23
Custom Fonts in iOS
import Foundation
/// Custom FontWeights to be used with the .font UIFont class functions
public enum FontWeight: String {
case regular = "Regular"
case medium = "Medium"
case black = "Black"
case light = "Light"
case thin = "Thin"
case bold = "Bold"
@Marcocanc
Marcocanc / UIFont+font.swift
Created June 15, 2017 12:23
Custom Fonts in iOS
import UIKit
extension UIFont {
/// Returns the font in the specified size and weight. Default weight is `regular`
open class func font(ofSize fontSize: CGFloat, weight: FontWeight = .regular) -> UIFont {
let fontName = "UniversNextPro-\(weight.rawValue)"
guard let font = UIFont(name: fontName, size: fontSize) else {
fatalError("\(fontName) not found")
}
return font
@Marcocanc
Marcocanc / ripe.sh
Created July 10, 2017 07:15
Domain to Ripe Lookup
#!/bin/bash
IP=$(dig +short $1 | sed -n 1p)
whois -h whois.ripe.net -- "-T route ${IP}"