Skip to content

Instantly share code, notes, and snippets.

@joninsky
joninsky / FilterState.swift
Created February 2, 2022 17:59
SwiftUI Combine filter mapping
import Foundation
import Combine
class FilterState: ObservableObject {
@Published var filterId: String?
@Published var hasFilter: Bool = false
init() {
@joninsky
joninsky / UI.swift
Created April 22, 2020 23:36
YELPDEMOAPI
import SwiftUI
import CoreLocation
struct ContentView: View {
//Get the networking controller from the environment objects.
@EnvironmentObject var networkingController: ApolloNetworkingController
//Do the same with the location controller even though we could access this controller as a property of the network controller.
@EnvironmentObject var locationController: LocationController
//Swift UI Magic
@joninsky
joninsky / network.swift
Created April 22, 2020 20:46
Networking coordinator setup
class ApolloNetworkingController: ObservableObject {
@Published var businesses: [BusinessFragment] = []
@Published var businessesQueryRunning: Bool = false
@Published var businessesQueryError: Error?
@Published var searchText: String = "Food"
@joninsky
joninsky / info.xml
Last active April 22, 2020 20:42
plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yelp.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
@joninsky
joninsky / main.swift
Last active April 20, 2020 23:47
ApolloCodeGen
import ApolloCodegenLib
import FileProvider
let parentFolderOfScriptFile = FileFinder.findParentFolder()
//1) Get some directory references
//This is the directory that the entire project lives in.
let projectDirectory = parentFolderOfScriptFile.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
//This is the directory for the Codegen
let codegenDirectory = projectDirectory.appendingPathComponent("Codegen")
@joninsky
joninsky / Package.swift
Created April 20, 2020 23:43
Swift package definition for Apollo scripts.
import PackageDescription
let package = Package(
name: "Codegen",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "Apollo", url: "https://github.com/apollographql/apollo-ios.git", .upToNextMinor(from: "0.25.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@joninsky
joninsky / BusinessesGraphQL.graphql
Created April 20, 2020 23:23
BusinessesGraphQL
query Businesses($searchTerm: String, $latitude: Float, $longitude: Float) {
search(term: $searchTerm, latitude: $latitude, longitude: $longitude) {
business {
...BusinessFragment
}
}
}
fragment BusinessFragment on Business {
id
@joninsky
joninsky / yelpintrospection.sh
Created April 20, 2020 06:18
yelpintrospection
apollo schema:download --endpoint https://api.yelp.com/v3/graphql --header 'Authorization: Bearer <API KEY>'
@joninsky
joninsky / stack.yaml
Created August 25, 2019 22:55
ENV Naming example Cloudformation
RDSSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: !If ['IsProduction', 'api_rds', !Sub 'api_rds_${ENV}']
@joninsky
joninsky / stack.yaml
Created August 25, 2019 22:52
ENV tag example Cloudformation
RouteTableAPublic:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'Route Table public A - ${ENV}'