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
FROM busybox:latest | |
ENTRYPOINT sh -c "cd /tmp/hooks && ls | xargs chmod +x && cd /tmp/.git/hooks && find ../../hooks -type f -exec ln -sf {} /tmp/.git/hooks/ \; && echo 'githooks installed'" |
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
// First we define a standard generic structure for an api response | |
interface ApiMethodResponse<T> { | |
statusCode?: number | |
data: T | |
} | |
// The `apiMethod` constructor will take an `ApiMethodDefinition` as argument. | |
type ApiMethodDefinition<T> = (req: Request) => Promise<ApiMethodResponse<T>> | |
// Now the constructor: |
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
export const wrappedShowUser = apiMethod<{user?: User}>(async req => { | |
const user = await User.findOne({id: req.params.id}) | |
if (!user) {return {statusCode: 404}} | |
return { | |
statusCode: 200, | |
data: {user}, | |
} | |
}) |
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 { Request, Result } from 'express' | |
export async function showUser (req: Request, res: Result) { | |
try { | |
const user = await User.findOne({id: req.params.id}) | |
if (user) { | |
res.status(200).send({user}) | |
} else { | |
res.sendStatus(404) | |
} |
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
exports.showUser = function (req, res) { | |
User.findOne({id: req.params.id}, (err, user) => { | |
if (err) { res.status(500).send({err}) } | |
if (user) { | |
res.status(200).send({user}) | |
} else { | |
res.sendStatus(404) | |
} | |
}) | |
} |
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 addOne (i: number): number { return i + 1 } | |
addOne('1') |
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
transpiler: | |
build: . | |
volumes_from: | |
- data | |
# typescript should watch the src directory | |
command: tsc -w --outDir dist/ ./src/index.ts | |
server: | |
build: . | |
volumes_from: |
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
# smart people already figured out how to install node | |
FROM mhart/alpine-node:7 | |
# create a work directory inside the container | |
RUN mkdir /app | |
WORKDIR /app | |
# install utilities. I currently like yarn | |
RUN npm install -g yarn nodemon tsc | |
# install dependencies |
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
asyncGreet () { | |
this.someThingAsync() | |
.then(() => { | |
this.greet() | |
}) | |
} |
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
class Foo { | |
constructor (name) { | |
this.name = name | |
this.greet = this.greet.bind(this) | |
} | |
} |