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 / listfont.swift
Created June 28, 2018 08:54
Listing out all included fonts in your app
// Make sure to include font files in bundle
// Add "Fonts provided by application" / UIAppFonts to Info.plist (use filename)
// Run this snippet in AppDelegate to find the name of your fonts
UIFont.familyNames.forEach { family in
print(family)
UIFont.fontNames(forFamilyName: family).forEach { names in
print(" - ", names)
}
}
@ksmandersen
ksmandersen / FairPlayer.swift
Created April 9, 2018 07:51 — forked from fousa/FairPlayer.swift
Integrate HLS with FairPlay.
class FairPlayer: AVPlayer {
private let queue = DispatchQueue(label: "com.icapps.fairplay.queue")
func play(asset: AVURLAsset) {
// Set the resource loader delegate to this class. The `resourceLoader`'s delegate will be
// triggered when FairPlay handling is required.
asset.resourceLoader.setDelegate(self, queue: queue)
// Load the asset in the player.
@ksmandersen
ksmandersen / withInitialData.js
Last active 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 from 'react';
const hasDataForKey = (staticContext) => (key) => staticContext && Object.keys(staticContext.data).includes(key);
const windowHasDataForKey = (window) => (key) => Object.keys(window.__DATA__).includes(key);
export default ({ key, prop, getData }) => (WrappedComponent) => {
class SSRCompatibleComponent extends React.Component {
constructor(props) {
super(props);
this.state = {};
@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,
@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 / 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 / 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 / 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) {
+ 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
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