Skip to content

Instantly share code, notes, and snippets.

View nguyendangminh's full-sized avatar

Nguyen Dang Minh nguyendangminh

View GitHub Profile
@nguyendangminh
nguyendangminh / nginx
Last active May 26, 2019 08:00
nginx cookbook
# Dirty configuration for hosting multiple websites on the same server. Note: Just for development only
## Add /etc/nginx/sites-enabled/myconfig
server{
server_name website1.com;
location / {
proxy_pass http://127.0.0.1:8888;
}
}
server{
server_name website2.com;
@nguyendangminh
nguyendangminh / django-cookbook.py
Last active August 29, 2015 14:21
Django cookbook
# Migration
$ python manage.py makemigrations <app_name>
$ python manage.py migrate <app_name>
# Time zone for Vietnam
## Change in settings.py
TIME_ZONE = 'Asia/Ho_Chi_Minh'
@nguyendangminh
nguyendangminh / django-boostrap.py
Last active August 29, 2015 14:21
Django bootstrap
$ sudo pip install pip
$ sudo pip install django
$ sudo apt-get install python-mysqldb
$ django-admin startproject <project>
# Edit settings.py
INSTALLED_APPS = (
'<project>',
...
@nguyendangminh
nguyendangminh / mysql.sql
Last active April 7, 2017 07:44
MySQL cookbook
# Create database for storing Vietnamese
mysql> CREATE DATABASE `dbname` CHARACTER SET utf8 COLLATE utf8_general_ci;
# Export and import database
$ mysqldump -u username -p dbname > db_backup.sql
$ mysql -u username -p -h hostname dbname < data.sql
# Display each row of the query result in line-by-line instead of table format:
mysql> select * from tablename \G;
@nguyendangminh
nguyendangminh / django-ckeditor.py
Last active August 29, 2015 14:21
django-ckeditor
# https://github.com/django-ckeditor/django-ckeditor
$ sudo pip install django-ckeditor
# Edit settings.py
Add 'ckeditor' to your INSTALLED_APPS setting.
Add:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # <app_dir>/static
MEDIA_URL = '/static/uploads/'
@nguyendangminh
nguyendangminh / run.sh
Created April 30, 2015 12:51
Shell starter
#!/bin/sh
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd)
"$SCRIPTPATH/bhm" -importPath bhm -srcPath "$SCRIPTPATH/src" -runMode prod
@nguyendangminh
nguyendangminh / json-config.go
Created March 3, 2015 04:02
Configuration by JSON in Golang
import (
"os"
"log"
"fmt"
"flag"
"encoding/json"
)
type Configuration struct {
Host string
@nguyendangminh
nguyendangminh / gist.go
Created December 28, 2014 18:07
Gist for Golang
// Logging
import (
"log"
"time"
)
func response(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("Hello world!"))
log.Printf(time.Now().String(), r.Method, r.URL.String())
}
@nguyendangminh
nguyendangminh / bash.sh
Created December 22, 2014 07:53
Gist for Bash
# Get path of directory in which the script is stored
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd )
echo $DIR
# Use content of a file as argument
kill -9 $(<./thin.pid)
@nguyendangminh
nguyendangminh / rvm.sh
Last active August 29, 2015 14:11
RVM - Ruby Version Manager
# Note:
# RVM does not control the system Ruby or its gems. Only Rubies and gems installed by RVM are under it's control!
# Install RVM
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby
$ source /home/ubuntu/.rvm/scripts/rvm
# Install a Ruby version
$ rvm install ruby-1.9.3