Skip to content

Instantly share code, notes, and snippets.

View andyyhope's full-sized avatar

Andyy Hope andyyhope

View GitHub Profile
# tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# alias
source ~/.git-prompt.sh
source ~/.git-completion.bash
alias ls='ls -FGalh'
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
UIEdgeInsets separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
// Remove seperator inset
if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
[self setSeparatorInset:separatorInset];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([self respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[self setPreservesSuperviewLayoutMargins:NO];
public class func drawConnectionError(frame frame: CGRect = CGRect(x: 0, y: -0, width: 66, height: 46)) {
//// Color Declarations
let fillColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
let fillColor2 = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 0.204)
let fillColor3 = UIColor(red: 0.996, green: 0.792, blue: 0.180, alpha: 1.000)
//// Subframes
let group: CGRect = CGRect(x: frame.minX + floor(frame.width * 0.01153 - 0.26) + 0.76, y: frame.minY + floor(frame.height * 0.01752 + 0.25) + 0.25, width: floor(frame.width * 0.98712 + 0.35) - floor(frame.width * 0.01153 - 0.26) - 0.61, height: floor(frame.height * 0.99457 + 0.31) - floor(frame.height * 0.01752 + 0.25) - 0.06)
private static func nameFor(notification: Notification) -> String {
return "\(self).\(notification.rawValue)"
}
static func addObserver(observer: AnyObject, selector: Selector, notification: Notification) {
let name = nameFor(notification)
NSNotificationCenter.defaultCenter()
.addObserver(observer, selector: selector, name: name, object: nil)
}
static func removeObserver(observer: AnyObject, notification: Notification, object: AnyObject? = nil) {
let name = nameFor(notification)
NSNotificationCenter.defaultCenter()
.removeObserver(observer, name: name, object: object)
}
static func postNotification(notification: Notification, object: AnyObject? = nil, userInfo: [String : AnyObject]? = nil) {
let name = nameFor(notification)
NSNotificationCenter.defaultCenter()
.postNotificationName(name, object: object, userInfo: userInfo)
}
extension Selector {
static let coffeeMadeNotification = #selector(Customer.drink(_:))
}
class Customer {
@objc func drink(notification: NSNotification) {
print("Mmm... Coffee")
}
}
func instantiateViewController<T: UIViewController>() -> T where T: StoryboardIdentifiable {
guard let viewController = self.instantiateViewController(withIdentifier: T.storyboardIdentifier) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
}
return viewController
}
struct Foo { }
enum Bar {
case hero(Any)
}
let foo = Foo()
let bar = Bar.hero(foo)
if case let .hero(foo) = bar, foo is Foo {