Skip to content

Instantly share code, notes, and snippets.

View thuongdinh-agilityio's full-sized avatar
🎯
Focusing

Thuong Dinh thuongdinh-agilityio

🎯
Focusing
View GitHub Profile

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

# This shows the setup for two services, an accounts service which connects to a database and a pagerduty service which connects to the pagerduty api
# Directory structure
accounts/
|_ Dockerfile
pagerduty/
|_ Dockerfile
nginx/
|_ conf/
|_ sites.conf
|_ .htpasswd
@thuongdinh-agilityio
thuongdinh-agilityio / postgresql_create_database_grant_user.sh
Last active December 9, 2015 15:01
postgresql_create_database_grant_user
sudo -u postgres psql -tAc "CREATE DATABASE jerry;"
sudo -u postgres psql -tAc "GRANT ALL PRIVILEGES ON DATABASE jerry to tom;"
@thuongdinh-agilityio
thuongdinh-agilityio / install_docker-compose.sh
Last active December 9, 2015 15:00
bash_installation_scripts_ubuntu
sudo apt-get install python-pip -y
sudo pip install -U docker-compose==1.4.0
o := orm.NewOrm()
//Database alias
name := "default"
// Drop table and re-create.
force := true
// Print log.
verbose := true
err := orm.RunSyncdb(name, force, verbose) //this is to create/drops the tables
if err != nil {
beego.Info(err)
@thuongdinh-agilityio
thuongdinh-agilityio / dockerfile_nodejs_4x
Last active December 9, 2015 14:59
docker_simple_nodejs_4x
FROM node:4
# Add code & set working dir
ADD . /app
WORKDIR /app
# Install npm package
RUN npm install
@thuongdinh-agilityio
thuongdinh-agilityio / docker_macos
Created December 1, 2015 07:24
How to install docker on macosx
# install brikis98/docker-osx-dev
curl -o /usr/local/bin/docker-osx-dev https://raw.githubusercontent.com/brikis98/docker-osx-dev/master/src/docker-osx-dev
chmod +x /usr/local/bin/docker-osx-dev
docker-osx-dev install
# go to working folder where contains docker-compose.xml
docker-osx-dev
# install virtualenv
sudo pip install virtualenv
@thuongdinh-agilityio
thuongdinh-agilityio / Vagrantfile
Last active December 9, 2015 14:58
Simple Vagrantfile for development
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 1
@thuongdinh-agilityio
thuongdinh-agilityio / docker-machine_create_generic_driver_multiple_host
Created January 18, 2016 08:45
Create docker machine use generic driver with existing cert
docker-machine \
--tls-ca-cert $LOCAL_CONFIG_PATH/ca.pem \
--tls-ca-key $LOCAL_CONFIG_PATH/ca-key.pem \
--tls-client-cert $LOCAL_CONFIG_PATH/cert.pem \
--tls-client-key $LOCAL_CONFIG_PATH/key.pem \
create --driver generic --generic-ssh-user root --generic-ip-address xxx.xxx.xxx.xxx test-deployment