Run Ruby on Rails App for the first time only with nginx

So I’m just lazy, I know there is better way to serve Ruby on Rails with unicorn or uWSGI, but I will try later.

This time I just want a have a quick look how’s the RoR running on the browser only with nginx, just a quick guide, no bullshit. so currently I have rails installed on my ubuntu machine 14.04 with mysql database configured and nginx. So make sure you have those things installed properly to follow this guide.

I usually create my local domain first to navigate it easier:

$ sudo echo -e "\tmyapp.local" >> /etc/hosts

Create the nginx config for your web app :

$ sudo vim /etc/nginx/conf.d/myapp.conf

very simple myapp.conf looks like:

server {
 listen 80;
 server_name www.myapp.local myapp.local;
 charset utf-8;
 access_log /var/log/nginx/myapp.access.log;
 error_log /var/log/nginx/myapp.error.log;
 location / {

Check nginx config and restart

$ sudo nginx -t
$ sudo service nginx restart

Run the rails (I told you, I’m just lazy) :

$ cd /myapp
$ rails server &

And now, Rails is running with port 3000 which nginx already addressed to myapp.local domain. Open up the browser and navigate to http://myapp.local

Setup Ruby On Rails on Ubuntu 14.04 Trusty Tahr

I’m sick of people who write tutorials which is not clear to install the Rails, too long, too much multiple choice, rambling. This is tutorial that actually works for me. Hope it would work for you too.

Install some dependencies first

$ sudo apt-get update
$ sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs

And we install the ruby, the current new version when this post is written is ruby 2.4.1, you might want to change with the newer version if available.

$ wget
$ tar xzvf ruby-2.4.1.tar.gz
$ cd ruby-2.4.1
$ ./configure
$ make
$ sudo make install

Check the ruby version

$ ruby -v

Install bundler and Rails with gem

$ sudo gem install bundler
$ sudo gem install rails

Check the Rails version

$ rails -v

Create new app

$ rails new my_new_app

How to set static file in django with templateview

Sometimes I got confused whether to set my static file with nginx or just inside the Django.

This is how I do it inside in django app directory.

from django.views.generic import TemplateView

urlpatterns = {
    url(r'^static\.txt$', TemplateView.as_view(template_name='files/static.txt', content_type='text/plain')),

and navigate to

Unfollow all your friends on twitter with this simple code

You go to twitter, and select your following and scroll all the way down until it reaches the bottom, you can hold on the Page Down button to be more efficient.

If it reaches the bottom of the page, open up the console or if you use chrome, press Ctrl+Shift+J, select console tab, and paste this code:

[]'.unfollow-text')).forEach(function(button) {;

nailed it.

How to check connection in android

This is how to check connection in android whether your phone is connected to the internet or not. put this function inside your public class.

private boolean isConnected() {
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected())
            return true;
            return false;


Git cheatsheet

list branch

git branch

move to another branch

git checkout your-branch

hard reset branch

git reset --hard origin/master

create new branch

git checkout -b new-branch

delete local branch

git branch -D your-branch

merge from develop to master

git merge develop

init on existed project and push master for the first time

git init
git remote add origin ssh://
git add .
git commit -am "initial commit"
git push -u origin master

Start VM in virtualbox headless mode

I want to start my VM virtualbox but without the GUI interface, cause if I need to get the access to my VM, I just can SSH into it. So it won’t need any GUI interface and I don’t have to open up Virtualbox first to start my VM.

This is a simple command line to start up your VM in headless mode, once it gets started, you can just SSH into your VM.

VBoxManage startvm myubuntu --type headless

Poweroff your VM with command line:

VBoxManage controlvm myubuntu poweroff

Or you can just init 0 in your VM when you’re done, LOL

Get json results from mysql with python

This is just simple trick to retrieve data from mysql rows and turn into json.

#!/usr/bin/env python
import MySQLdb as mdb
import sys

con = mdb.connect('localhost', 'root', 'pass123', 'mydb1', charset='utf8')
cur = con.cursor(mdb.cursors.DictCursor)

def get_post():
    list = []
    gw = {}
    cur.execute("select * from tbl1_core")
    rows = cur.fetchall()
    for i in rows:
        tes = []
        # we want to fetch row to store in results
        gw["content"] = i["content"]
        tes = []
        gw = {}
    return list
tes = get_post()
print tes

Setup docker + jenkins + nginx

Let’s setup jenkins with docker with local url : jenkins.local

First, add local url to /etc/hosts

$ sudo echo -e "\tjenkins.local" >> /etc/hosts

Install docker and pull newest jenkins image

$ sudo apt-get install
$ sudo docker pull jenkins
$ sudo docker run -itd --name jenkins --publish 8080:8080 --publish 50000:50000 jenkins

Setup nginx

$ sudo vim /etc/nginx/conf.d/jenkins.conf

nginx conf:

server {
  listen 80;
  server_name jenkins.local;
  charset utf-8;
  gzip_vary on;
  access_log /var/log/nginx/jenkins.access.log;
  error_log /var/log/nginx/jenkins.error.log;
  location / {

Save config and restart nginx

$ sudo service nginx restart

Open browser, and navigate to http://jenkins.local