Skip to content

Instantly share code, notes, and snippets.

View guillianbalisi's full-sized avatar

Guillian Balisi guillianbalisi

View GitHub Profile
@guillianbalisi
guillianbalisi / CoreDataGettable.swift
Last active December 19, 2018 21:43
Protocol to make fetching model objects from core data easier
import Foundation
import CoreData
protocol CoreDataGettable where Self: NSManagedObject {
static func getSingle(id: String, context: NSManagedObjectContext) -> Self?
static func getList(accId: String, context: NSManagedObjectContext) -> [Self]
static func getSingle(withPredicate predicate: String, args: CVarArg, context: NSManagedObjectContext) -> Self?
}
extension CoreDataGettable {
@guillianbalisi
guillianbalisi / UIImageView+ImageDownloading.swift
Last active August 21, 2018 15:09
Downloading images from a URL for a UIImageView with caching
extension UIImageView {
/// Loads image from web asynchronosly and caches it, in case you have to load url
/// again, it will be loaded from cache if available
/// - parameter url: URL for the image
/// - parameter placeholder: Placeholder image to use while image is downloading, defaults to nil
/// - parameter template: True to use template image rendering mode, false to use original image
/// rendering mode, defaults to false
func load(url: URL, placeholder: UIImage? = nil, template: Bool = false) {
let cache = URLCache.shared
let request = URLRequest(url: url)
@guillianbalisi
guillianbalisi / .bash_profile
Created August 12, 2018 16:02
Bash profile
export CLICOLOR=1
bind "set completion-ignore-case on" # Persists tab-completion case-insensitive
bind "set show-all-if-ambiguous on" # Persists tab-completion case-insensitive
# -----------------------------
# MAKE TERMINAL BETTER
# -----------------------------
alias nosleep='caffeinate -d -i -s -u'
@guillianbalisi
guillianbalisi / UIButton+AnimatedSetImage.swift
Created July 12, 2018 18:38
Change the image of UIButton with a bounce animation (reversible, for example liking/unliking with a heart image)
extension UIButton {
func setImage(_ image: UIImage?, animated: Bool = false, reversed: Bool = false, color: UIColor) {
guard animated else {
setImage(image, for: .normal)
return
}
let templateImage = image?.withRenderingMode(.alwaysTemplate)
tintColor = color