Skip to content

Instantly share code, notes, and snippets.

View Amzd's full-sized avatar
🚀

Casper Zandbergen Amzd

🚀
View GitHub Profile
/**
A default implmentation that provides a few convenience methods for starting and stopping coordinators.
*/
extension Coordinator {
// Default implementation, so that we don't have to do this for all coordinators.
func startChild<T: NSObject where T: Coordinator>(coordinator coordinator: T, withIdentifier identifier: String, callback: CoordinatorCallback?) -> T {
childCoordinators[identifier] = coordinator
coordinator.start(withCallback: callback)
return coordinator
@brygrill
brygrill / firebase-graphql-with-data.js
Last active March 3, 2021 23:00
Deploying a GraphQL Server with Firebase Functions
// sample graphql server deployed with firebase functions
// pulling some basic stockmarket data from a firebase db
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const values = require('lodash.values');
const { GraphQLSchema, GraphQLObjectType, GraphQLList, GraphQLString } = require('graphql');
// Init express
@danlozano
danlozano / Coordinator.swift
Last active September 26, 2018 07:19
Coordinator Class
class Coordinator {
private(set) var childCoordinators: [Coordinator] = []
func start() {
preconditionFailure("This method needs to be overriden by concrete subclass.")
}
func finish() {
preconditionFailure("This method needs to be overriden by concrete subclass.")
import Foundation
import UIKit
public protocol Configure {}
extension Configure {
/// Makes it available to set properties with closures just after initializing.
///
/// let frame = UIView().configure {
@casperzandbergenyaacomm
casperzandbergenyaacomm / EmptyOrNil.swift
Last active November 12, 2021 08:10
Adding readability for an if statement I often use.
protocol EmptyOrNil {
var isEmpty: Bool { get }
}
extension Optional where Wrapped: EmptyOrNil {
var isEmptyOrNil: Bool {
return self?.isEmpty ?? true
}
}
@noxt
noxt / NSObject+Configurable.swift
Created March 18, 2019 19:35
NSObject+Configurable
import Foundation
protocol InitConfigurable {
init()
}
extension InitConfigurable {
init(configure: (Self) -> Void) {
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@SpectralDragon
SpectralDragon / PreviewContextMenu.swift
Created April 8, 2020 19:22
Simple way to implement preview context menu for SwiftUI
//
// ContentView.swift
// PreviewSwiftUI
//
// Created by v.prusakov on 4/8/20.
// Copyright © 2020 v.prusakov. All rights reserved.
//
import SwiftUI
@khanlou
khanlou / YouDeserveNiceErrors.swift
Last active October 18, 2020 03:00
Nicer descriptions for DecodingErrors
extension DecodingError.Context {
var pathDescription: String {
pathDescription(for: codingPath)
}
func path(including final: CodingKey) -> String {
pathDescription(for: codingPath + [final])
}
private func pathDescription(for path: [CodingKey]) -> String {
@rnystrom
rnystrom / example.swift
Created January 18, 2021 00:30
Show the keyboard as a UISearchController in a modal is displayed
class ViewController: UIViewController {
@IBAction func onSearch(_ sender: Any) {
let fakeWindow = UIWindow(windowScene: view.window!.windowScene!)
let fakeTextField = UITextField()
fakeTextField.autocorrectionType = .no
fakeWindow.addSubview(fakeTextField)
fakeWindow.makeKeyAndVisible()
fakeTextField.becomeFirstResponder()