This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Calculate the L2 Norm **/ | |
func l2Normalization(vector: [Double]) -> Double { | |
var sum: Double = 0 | |
for i in vector { | |
sum += pow(i, 2) | |
} | |
return sqrt(sum) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |