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
// SkyClip | |
// - GenericTypeResolver.cs | |
// -------------------------------------------------------------------- | |
// Author: Jeff Hansen <jeff@jeffijoe.com> | |
// Copyright (C) Jeff Hansen 2015. All rights reserved. | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; |
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
/* | |
The MIT License | |
Copyright (c) Jeff Hansen 2018 to present. | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION W |
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
# This script will completely remove the Docker virtual disk (I guess?). Relaunch Docker for Mac to rebuild it. | |
# Why do you need this? If you're building Node apps in Docker, eventually you might get the ´no space left on device` | |
# error. You can use ` docker rm $(docker ps -q -f 'status=exited'); docker rmi $(docker images -q -f "dangling=true")` | |
# but that only works a few times. The command below is a complete reset, and will nuke your containers and images. | |
rm -rf ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2 |
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
import Koa from 'koa' | |
import parse from './busboy' | |
import AWS from 'aws-sdk' | |
const app = new Koa() | |
const s3 = new AWS.S3({ | |
params: { Bucket: 'myBucket' } | |
}) |
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
// middleware/auth.js | |
export default async function authenticate (ctx, next) { | |
// Do your auth stuff here. | |
const decoded = extractTokenSomehow(ctx) | |
const teamId = decoded.teamId | |
const userId = decoded.userId | |
// Use the User Repository and Team Repository (or a cache?) to fetch | |
// our entities. | |
// Resolve instances of these using Awilix's cradle proxy. |
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
import Koa from 'koa' | |
import KoaRouter from 'koa-router' | |
import { asValue } from 'awilix' | |
import { scopePerRequest, makeInvoker } from 'awilix-koa' | |
import configureContainer from './configureContainer' | |
const app = new Koa() | |
const router = new KoaRouter() | |
const container = configureContainer() |
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
import { createContainer, asClass, asFunction } from 'awilix' | |
import makeTodosService from './todosService' | |
import TodosRepository from './todosRepository' | |
export default function configureContainer () { | |
const container = createContainer() | |
// Ordering does not matter. | |
container.register({ | |
// Notice the scoped() at the end - this signals |
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
const router = new KoaRouter() | |
router.get('/todos', async (ctx) => { | |
const todosService = makeTodosService({ | |
todosRepository: new TodosRepository(), | |
// Our Koa request knows about the current user | |
currentUser: ctx.state.user | |
}) | |
ctx.body = await todosService.getTodos(ctx.request.query) |
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
const currentUser = { | |
id: 123, | |
name: 'Jeff' | |
} | |
const todosRepository = new TodosRepository() | |
const todosService = makeTodosService({ | |
todosRepository, | |
currentUser |
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
import makeTodosService from './todosService' | |
import TodosRepository from './todosRepository' | |
describe('Todos System', function () { | |
it('works', async function () { | |
// This is how DI is done manually | |
const todosService = makeTodosService({ | |
todosRepository: new TodosRepository(), | |
// Let's fake it til we make it! | |
currentUser: { |
NewerOlder