Skip to content

Instantly share code, notes, and snippets.

View Nomad-Go's full-sized avatar

Nomad-Go

View GitHub Profile
@Nomad-Go
Nomad-Go / Cell.swift
Created November 30, 2020 02:01
Cell for upload object.
public struct TransferableObjectCell: View {
//MARK: State and binding properties
var viewModel: S3Transferable
@State var progress: Double = 0
@State var status: AWSS3TransferUtilityTransferStatusType = AWSS3TransferUtilityTransferStatusType.unknown
//MARK: Computed Properties
@Nomad-Go
Nomad-Go / Upload.swift
Created November 30, 2020 01:33
Upload protocol
/// An object that will be transfered to or from S3
public protocol S3Transferable: class {
//A unique identifier for this object
var id: UUID { get }
//The key for the object in S3
var objectCloudKey: String { get }
//A CurrentValueSubject that will publish the progress as a Double and never fail
var progress: CurrentValueSubject<Double, Never> { get }
//The object returned by AWS that will give us access to some functionality and status.
var task: AWSS3TransferUtilityTask? { get set }
@Nomad-Go
Nomad-Go / Uploads.swift
Last active November 1, 2022 03:07
Combine S3 Uploads
/// Function that will take an Array of `[S3Uploadable]` objects and returns a publisher that will complete once all uploads are done.
/// - Parameter objects: An array of `S3Uploadable` objects
/// - Returns: An `AnyPublisher` that will publish the array of objects you passed in and a faileur type of `Never`
public func upload(uploadableObjects objects: [S3Uploadable]) -> AnyPublisher<[S3Uploadable], Error> {
//We will collect some Futures into an array
var futures: [Future<S3Uploadable, Error>] = []
//Collect the futures
for object in objects {
let future = self.upload(objectToUpload: object)
@Nomad-Go
Nomad-Go / GMMenu_Usage.swift
Last active April 3, 2020 01:38
Shows basic usage of my SwiftUI menu implementation
import SwiftUI
import GridMenu
struct ContentView: View {
//1) I abstracted out the variables that help control the menu behavior and state so that it's easier to manage in the scope of your project
@ObservedObject var gmMenuController = GMMenuController()
var body: some View {
@Nomad-Go
Nomad-Go / index.js
Created January 23, 2019 17:56
Singed S3 Lambda
'use strict';
console.log('Loading function');
const aws = require('aws-sdk');
const s3 = new aws.S3({signatureVersion: 'v4'});
exports.handler = (event, context, callback) => {
const bucket = process.env.S3_BUCKET_NAME;
@Nomad-Go
Nomad-Go / L2Norm.swift
Created January 14, 2019 21:39
Calculate the L2 Norm of a `[Double]` value in Swift
/** Calculate the L2 Norm **/
func l2Normalization(vector: [Double]) -> Double {
var sum: Double = 0
for i in vector {
sum += pow(i, 2)
}
return sqrt(sum)
}