Skip to content

Instantly share code, notes, and snippets.

View khalidx's full-sized avatar
💭
Engineering for the ☁️

Khalid Zoabi khalidx

💭
Engineering for the ☁️
View GitHub Profile
@khalidx
khalidx / api.ts
Last active May 19, 2021 11:52
A quick api boilerplate file for express with hot-reloading and typescript support
#!/usr/bin/env node
/* The API routes and middlewares */
const server = () => import('express').then(({ default: express }) => {
const app = express()
app.get('/hello', (req, res) => {
res.json({ message: 'Hey there!' })
})
return app
})
@khalidx
khalidx / banner.md
Created June 25, 2020 16:34
Shows a banner on the CLI using a cool font

banner

Shows a banner on the CLI using a cool font.

For NodeJs & TypeScript. Depends on the amazing figlet and chalk libraries.

import figlet from 'figlet'
import chalk from 'chalk'
@khalidx
khalidx / typescript-config.md
Created June 18, 2020 03:08
Add a TypeScript config to your project easily

typescript config

Make sure to install the following dependencies for the best experience.

npm install --save tslib
npm install --save-dev typescript
npm install --save-dev ts-node
@khalidx
khalidx / vpc.tf
Created June 10, 2020 02:09
Simple, quick, and complete VPC setup for AWS
locals {
region = "us-east-1"
namespace = "infrastructure"
}
provider "aws" {
region = local.region
}
module "vpc" {
@khalidx
khalidx / event.ts
Created May 10, 2020 13:20
A typed event emitter for TypeScript
// This lets you emit and listen for events in a type-safe manner
// Awesome!
import { EventEmitter } from 'events'
type Type<Name> = { type: Name }
type Value<Type> = { value: Type }
export type TypedValue<T, V> = Type<T> & Value<V>
@khalidx
khalidx / status.sh
Created April 11, 2020 01:46
Check the exit status code of a shell command
whoami # run some command
echo $? # show the exit status code result of the command
@khalidx
khalidx / index.ts
Last active July 29, 2020 09:25
Using lowdb with TypeScript; instantly instantiates a typed db with defaults and compile-time-checked queries
import low from 'lowdb'
import FileSync from 'lowdb/adapters/FileSync'
export const database = <T> (defaults: T) => {
const adapter = new FileSync<T>('db.json')
const db = low(adapter)
db.defaults(defaults).write()
return db
}
@khalidx
khalidx / dynamodb.ts
Created August 2, 2019 02:28
DynamoDb utility for usage in TypeScript with serverless-offline
import AWS from 'aws-sdk'
export default (process.env.IS_OFFLINE)
? new AWS.DynamoDB.DocumentClient({
region: 'localhost',
endpoint: 'http://localhost:8000',
accessKeyId: 'NONE',
secretAccessKey: 'NONE'
})
: new AWS.DynamoDB.DocumentClient()
@khalidx
khalidx / README.md
Last active July 1, 2019 05:26
Publishing to NPM

Increments the version and creates a git tag, pushes the tags to the remote, then publishes to npm.

npm version patch
git push && git push --tags
npm publish
@khalidx
khalidx / clear.js
Last active June 24, 2019 04:26
Clears the console (terminal), using Node.js
process.stdout.write('\x1b[2J');
process.stdout.write('\x1b[0f');