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 / 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 / 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 / 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 / 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-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 / 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-createtodo.ts
Last active May 22, 2020 18:17
serverless-todo-createtodo
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 { name } = JSON.parse(event.body);
const id = uuid.v4();
@robertofrontado
robertofrontado / serverless-todo-todorepository.ts
Created May 22, 2020 16:59
serverless-todo-todorepository
import * as AWS from 'aws-sdk'
import { DocumentClient } from 'aws-sdk/clients/dynamodb'
import { TodoItem } from '../models/TodoItem'
export default class TodoRepository {
constructor(
private readonly docClient: DocumentClient = createDynamoDBClient(),
private readonly todoTable = process.env.TODOS_TABLE) {
@robertofrontado
robertofrontado / serverless-todo-todoservice.ts
Last active May 22, 2020 17:16
serverless-todo-todoservice
import * as uuid from 'uuid'
import TodoRepository from '../repositories/TodoRepository'
import { TodoItem } from '../models/TodoItem'
export default class TodoService {
todoRepository: TodoRepository;
@robertofrontado
robertofrontado / serverless-todo-createtodo-with-service.ts
Created May 22, 2020 17:11
serverless-todo-createtodo-with-service
import 'source-map-support/register'
import { APIGatewayProxyHandler, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
import TodoService from '../../services/todoService'
export const handler: APIGatewayProxyHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
const { name } = JSON.parse(event.body)
const todoService = new TodoService()
const todo = await todoService.createTodo(name)