Skip to content

Instantly share code, notes, and snippets.

View archieedwards's full-sized avatar

Archie archieedwards

View GitHub Profile
@archieedwards
archieedwards / YourLibraryView_simple_SpotifySwiftUI.swift
Last active June 9, 2020 13:08
base structure for the Your Library view..
struct YourLibraryView: View {
@State var page: Int = 0 //// keeps track of which category index we are at
@State var nestedPages: [Int] = [0, 0] /// keeps track of which sub category index we are at for each category
@State var indicatorOffsets : [CGFloat] = [0,0] /// keepts track of indicator offsets for each category
var data = Array(0..<2)
var nestedData = Array(0..<3)
var body: some View {
@archieedwards
archieedwards / YourLibraryView_categorySwipe_SwiftUI.swift
Last active June 9, 2020 14:00
code to enable swiping through categories
.onPageChanged({ _ in
self.allowSubCategoryDragging = true
})
.swipeInteractionArea(.allAvailable)
.simultaneousGesture(DragGesture().onChanged({value in
/// catch moving to category
if self.allowSubCategoryDragging {
let movingCategoryRight = self.page == 0 && self.nestedPages[self.page] == 2 && value.translation.width < 0
let movingCategoryLeft = self.page == 1 && self.nestedPages[self.page] == 0 && value.translation.width > 0
if movingCategoryRight || movingCategoryLeft{
.simultaneousGesture(DragGesture().onChanged({value in
/// catch moving to category
if self.allowSubCategoryDragging {
let movingCategoryRight = self.page == 0 && self.nestedPages[self.page] == 2 && value.translation.width < 0
let movingCategoryLeft = self.page == 1 && self.nestedPages[self.page] == 0 && value.translation.width > 0
if movingCategoryRight || movingCategoryLeft{
self.allowSubCategoryDragging = false
}
else{
let westAsCanBe = self.nestedPages[self.page] == 0 && self.page == 0 && value.translation.width > 0
public final class NetworkClient {
private let session: URLSession = .shared
public init() { }
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) {
session.dataTask(with: request) { (data, _, error) in
if let error = error {
completion(.failure(error))
return
protocol NetworkClientProtocol {
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void)
}
extension URLSession: NetworkClientProtocol{
/// this is where the real request happens
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) {
let task = dataTask(with: request) { (data, _, error) in
completion(data, error)
}
protocol NetworkClientProtocol {
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void)
}
extension URLSession: NetworkClientProtocol{
/// this is where the real request happens
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) {
let task = dataTask(with: request) { (data, _, error) in
completion(data, error)
}
public final class NetworkClient {
private let n: NetworkClientProtocol
init(n: NetworkClientProtocol = URLSession.shared) {
self.n = n
}
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) {
n.executeRequest(request: request){ (data, error) in
if let error = error {
func testExecuteRequest_failure_noData() throws {
/// create mock to return nil
class NetworkMock : NetworkClientProtocol{
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) {
completion(nil, nil)
}
}
/// inject mock and execute request
@archieedwards
archieedwards / boom.go
Created February 6, 2021 13:00
This gist comes from the code in the testing-gist-automation repo. It was created automatically by GitTrack.
func GetDetails() string {
return "wow this is gonna be good"
}
@archieedwards
archieedwards / example-head.html
Created February 6, 2021 13:00
This gist comes from the code in the testing-gist-automation repo. It was created automatically by GitTrack.
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>