Skip to content

Instantly share code, notes, and snippets.

View robertofrontado's full-sized avatar
🐶
Working from home

Roberto Frontado robertofrontado

🐶
Working from home
View GitHub Profile
@robertofrontado
robertofrontado / erverless-todo-createtodo-isoffline.ts
Last active May 22, 2020 16:47
erverless-todo-createtodo-isoffline
import * as AWS from 'aws-sdk'
import 'source-map-support/register'
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
import * as uuid from 'uuid'
import { TodoItem } from '../../models/TodoItem'
export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
const data = JSON.parse(event.body);
const id = uuid.v4();
@robertofrontado
robertofrontado / serverless-todo-todoitem.ts
Last active May 22, 2020 16:20
serverless-todo-todoitem
export interface TodoItem {
id: string
name: string
done: boolean
createdAt: string
}
@robertofrontado
robertofrontado / serverless-todo-yml-dynamodb.yml
Last active May 25, 2020 09:40
serverless-todo-yml-dynamodb
service:
name: todo-api
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
plugins:
- serverless-webpack
@robertofrontado
robertofrontado / serverless-todo-yml-generated.yml
Created May 22, 2020 13:59
serverless-todo-yml-generated
service:
name: todo-api
# app and org for use with dashboard.serverless.com
#app: your-app-name
#org: your-org-name
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
@robertofrontado
robertofrontado / DI-usage-example.swift
Last active April 18, 2020 16:36
DI-usage-example
// Without DI
class Store {
static let shared = Store()
func save(key, String, value: Any) { /*...*/ }
func load(key: String) -> Any? { /*...*/ }
}
class ViewModel {
@robertofrontado
robertofrontado / Injected.swift
Created April 13, 2020 15:06
SwiftDI - Injected Without Caching
import Foundation
@propertyWrapper
public struct Injected<Value> {
public var wrappedValue: Value {
get {
SwiftDI.default.resolve()
}
}
@robertofrontado
robertofrontado / SwiftDIRegistration.swift
Last active April 13, 2020 15:03
SwiftDI - Registration
func registerDependencies() {
SwiftDI.configure {
$0.factory { Repository() }
}
}
@robertofrontado
robertofrontado / ClassWithSwiftDI.swift
Last active April 13, 2020 15:03
SwiftDI - Example
class Repository {}
class ViewModel {
@Injected var repository: Repository
}
@robertofrontado
robertofrontado / Injected.swift
Last active April 13, 2020 15:05
SwiftDI - Injected With Caching
import Foundation
@propertyWrapper
public struct Injected<Value> {
private var value: Value?
public var wrappedValue: Value {
get {
return value ?? SwiftDI.default.resolve()
@robertofrontado
robertofrontado / Resolver.swift
Created April 1, 2020 21:36
SwiftDI - Resolver
internal enum Resolver {
case single(object: Any)
case factory(block: () -> Any)
func resolve() -> Any {
switch self {
case .single(let object): return object
case .factory(let block): return block()
}
}