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 / PaddedTextField.swift
Last active July 18, 2024 09:44
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 / 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 / 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()
root@speakerdex:~# dokku --trace redis:backup speakerdex-sessions speakerdex-redis-backups
+ export DOKKU_DISTRO
++ . /etc/os-release
++ echo ubuntu
+ DOKKU_DISTRO=ubuntu
+ export DOKKU_IMAGE=gliderlabs/herokuish
+ DOKKU_IMAGE=gliderlabs/herokuish
+ export DOKKU_LIB_ROOT=/var/lib/dokku
+ DOKKU_LIB_ROOT=/var/lib/dokku
+ export PLUGIN_PATH=/var/lib/dokku/plugins
+ export DOKKU_DISTRO
++ . /etc/os-release
++ echo ubuntu
+ DOKKU_DISTRO=ubuntu
+ export DOKKU_IMAGE=gliderlabs/herokuish
+ DOKKU_IMAGE=gliderlabs/herokuish
+ export DOKKU_LIB_ROOT=/var/lib/dokku
+ DOKKU_LIB_ROOT=/var/lib/dokku
+ export PLUGIN_PATH=/var/lib/dokku/plugins
+ PLUGIN_PATH=/var/lib/dokku/plugins
@ksmandersen
ksmandersen / QueryPaginator.swift
Last active September 6, 2017 15:43
Paginate requests based on Fluent model queries in Vapor
import Foundation
import Vapor
import FluentProvider
struct Paginator<T: Model> where T: JSONRepresentable {
let query: Query<T>
let request: Request
let perPage: Int
init(query: Query<T>, request: Request, perPage: Int = 25) {
@ksmandersen
ksmandersen / install.sh
Created October 13, 2017 11:34
Install curl 7.56.0 with OpenSSL & HTTP2 support on Ubuntu 14.04.5 LTS
apt-get update
apt-get install -y build-essential curl
apt-get -y install git g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev libjemalloc-dev cython python3-dev python-setuptools
git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
automake
autoconf
./configure
make
@ksmandersen
ksmandersen / UIView+Helpers.swift
Last active November 7, 2017 10:09
Layout Anchor Helpers
import Foundation
import UIKit
extension UIView {
func addSubviews(_ subviews: [UIView]) {
for view in subviews {
addSubview(view)
}
}
}
@ksmandersen
ksmandersen / URI+Helpers.swift
Created January 24, 2018 09:41
Appending query parameters to URI's in Vapor
extension URI {
public func appendingQueryParameters(_ parameters: [String: String]) -> URI {
let allParameters = mergeParameters(queryParameters(fromQuery: query), rhs: parameters)
let newQuery = toQuery(parameters: allParameters)
return URI(scheme: scheme, userInfo: userInfo, hostname: hostname, port: port, path: path,
query: newQuery, fragment: fragment)
}
private func toQuery(parameters: [String: String]) -> String {
@ksmandersen
ksmandersen / withInitialData.js
Created February 8, 2018 19:52 — forked from armand1m/withInitialData.js
Simple HOC for fetching data that is compatible with the SSR technique described by @BenLu here: https://medium.com/@benlu/ssr-with-create-react-app-v2-1-ee83fb767327
import React, { Component } from 'react';
const hasDataForThisKey = (staticContext) =>
(key) => staticContext && Object.keys(staticContext.data).includes(key);
const windowHasDataForThisKey = (window) =>
(key) => Object.keys(window.__DATA__).includes(key);
export default ({
key,