Skip to content

Instantly share code, notes, and snippets.

View pedantix's full-sized avatar
😍
SWIFT!

Shaun Hubbard pedantix

😍
SWIFT!
View GitHub Profile
@pedantix
pedantix / JWTService.swift
Last active April 14, 2018 02:12
# Snippets For how I hacked together
import Foundation
import JWT
import Vapor
final class JWTService: Service {
var signer: JWTSigner
init(secret: String) {
signer = JWTSigner.hs512(key: Data(secret.utf8))
}
@pedantix
pedantix / Fluent3Eagerload.swift
Created February 22, 2018 21:50
A Futuristic Eagerload idea for fluent
// Per Tanner
let cache = \User.pets.prefetchCache()
let users = User.query(on: ...).filter(...).prefetching(\.pets, into: cache).all() // await
for user in users {
let pets = user.pets.get(from: cache)
}
// Shaun's idea
struct User: Model {
var pets: Childeren<User, Pet>?
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@pedantix
pedantix / MyThing.swift
Created November 11, 2017 22:55
Decodable Enum
// every now and then I really find an enum to be the right construct for a data model
// in this case events have "eventTypes" and using pattern matching on the eventType is desirable
// eventTypes are based on a serverside array of possibilities "[private, public]" but theree is the possibility that
// this would be added to serverside so this should not nesecarily break the client implemenation
// to deal with this we need an unknown case
enum EventType: String, Decodable {
case `private`
case `public`
case unknown
@pedantix
pedantix / BasicUsageExampleTests.swift
Created October 28, 2017 20:11
XCUIApplication testing with Ambasador in Swift 4
//
// BasicUsageExampleTests.swift
// ExampleUITests
//
// Created by Shaun Hubbard on 10/28/17.
// Copyright © 2017 Shaun Codes. All rights reserved.
//
import XCTest
import Ambassador
@pedantix
pedantix / makeUrlReq.swift
Created October 28, 2017 02:26
Swift 4 Encapsulate the URLRequests
// I needed to make a gist to show some things off and whats nots
import Foundation
enum HttpMethod: String {
case get = "GET"
case post = "POST"
case patch = "PATCH"
case delete = "DELETE"
}
@pedantix
pedantix / String.swift
Last active October 10, 2017 19:04
truncate by words swift 4
//
// String.swift
// MyModule
//
// Created by Shaun Hubbard on 10/9/17.
// Copyright © 2017 MyCompany, LLC. All rights reserved.
//
import Foundation
@pedantix
pedantix / bar.ex
Last active February 19, 2017 04:08
Using cast/3 with @optional_fields and @required_fields for simplicity
defmodule Splife.Bar do
use Splife.Web, :model
schema "bars" do
field :baz, :string
field :fizz, :string
timestamps()
end
// copy and paste into play ground
import UIKit
protocol ListViewModel {
associatedtype T:Comparable
var items: [T] { get set }
mutating func clear()
func item(forIndex index: NSIndexPath) -> T
@pedantix
pedantix / AcitivityMixin.swift
Last active April 9, 2016 15:56
Swift Activity View Mixin
//use whatever activity view makes you happy in this project we were converting from ObjC to Swift, #2016
protocol ActivityVC: class {
var activityView: DejalBezelActivityView? { get set }
var view: UIView! { get }
}
extension ActivityVC {
mutating func activityStart() {
if activityView == nil {
activityView = DejalBezelActivityView(forView: view, withLabel: nil, width: 40)