Skip to content

Instantly share code, notes, and snippets.

View aherve's full-sized avatar

Aurélien aherve

View GitHub Profile
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'"
// 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:
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},
}
})
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)
}
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)
}
})
}
function addOne (i: number): number { return i + 1 }
addOne('1')
transpiler:
build: .
volumes_from:
- data
# typescript should watch the src directory
command: tsc -w --outDir dist/ ./src/index.ts
server:
build: .
volumes_from:
# 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
asyncGreet () {
this.someThingAsync()
.then(() => {
this.greet()
})
}
class Foo {
constructor (name) {
this.name = name
this.greet = this.greet.bind(this)
}
}