Skip to content

Instantly share code, notes, and snippets.

View ksmandersen's full-sized avatar
🏠
Working from home

Kristian Andersen ksmandersen

🏠
Working from home
View GitHub Profile
@ksmandersen
ksmandersen / ImageCache.swift
Created May 30, 2017 08:00
Haneke & Swift image caching
import UIKit
import Forbind
import ForbindExtensions
import Haneke
typealias ImageProcess = (UIImage) -> UIImage
public class ImageCache {
public static let shared = ImageCache()
@ksmandersen
ksmandersen / ApplicationContext.swift
Created May 26, 2017 15:42
Coordinator Pattern in Swift
final class ApplicationContext {
// This is where you initialize most of the application stack
// that needs to be passed down to the coordinator chain for
// fetching data, and other important stuff.
// Example:
// let networkClient = NetworkClient()
}
@ksmandersen
ksmandersen / PaddedTextField.swift
Last active March 27, 2023 03:33
Best way to inset text inside a UITextField
import UIKit
open class PaddedTextField: UITextField {
public var textInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) {
didSet { setNeedsDisplay() }
}
public override init(frame: CGRect) {
super.init(frame: frame)
}
@ksmandersen
ksmandersen / .babelrc
Last active April 3, 2017 07:42
Vapor + Gulp + BrowserSync
{
"presets": ["es2015"]
}
@ksmandersen
ksmandersen / flac_to_alac.sh
Created January 5, 2017 08:55
FLAC to ALAC
for f in ./*.flac; do avconv -n -i "$f" -c:a alac "${f%.*}.m4a" && rm "$f"; done

Keybase proof

I hereby claim:

  • I am ksmandersen on github.
  • I am ksmandersen (https://keybase.io/ksmandersen) on keybase.
  • I have a public key whose fingerprint is AAA6 F6F2 F1B0 5FD0 A55B C524 2AF1 13BD 1A2B C11D

To claim this, I am signing this object:

# initialization file (not found)
let firstView = UIView()
let otherView = UIView()
// align.swift:
firstView.alignTop(20, to: otherView)
// vanilla:
firstView.topAnchor.constraint(equalTo: otherView.topAnchor, constant: 20)
public extension UIView {
func alignCenterX(_ constant: CGFloat = 0, multiplier: CGFloat = 1, to view: UIView,
attribute: NSLayoutAttribute = .centerX,
relation: NSLayoutRelation = .equal,
priority: UILayoutPriority = UILayoutPriorityRequired) -> NSLayoutConstraint {
return alignAttribute(attribute: .centerX, relation: relation,
to: view, otherAttribute: attribute,
multiplier: multiplier,
constant: constant, priority: priority)
}
import UIKit
import GenericViewKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let applicationController = ApplicationController()
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
applicationController.configureReporting()