“as_json” Rails

as_json has very flexible way to configure complex object according to model relations


Model campaign belongs to shop and has one list
Model list has many list_tasks and each of list_tasks has many comments
We can get one json which combines all those data easily.

        except: [:created_at, :updated_at],
        include: {
            shop: {
                except: [:created_at, :updated_at, :customer_id],
                include: {customer: {except: [:created_at, :updated_at]}}},
            list: {
                except: [:created_at, :updated_at, :observation_id],
                include: {
                    list_tasks: {
                        except: [:created_at, :updated_at],
                        include: {comments: {except: [:created_at, :updated_at]}}
        methods: :tags

Notice methods: :tags can help you attach any additional object which doesn’t have relations with others. You just need to define a method with name tags in model campaign. This method should return whatever you need (e.g. Tags.all)

Official documentation for as_json

RVM – Gemsets

Creating gemsets

Gemsets must be created before being used. To create a new gemset for the current ruby, do this:
rvm 2.1.1
rvm gemset create teddy
Gemset 'teddy' created.

Alternatively, if you prefer the shorthand syntax offered by rvm use, employ the –create option like so:
rvm use 2.1.1@teddy --create

Select gemsets according to the Project

There is a new way to do this, without having to allow arbitrary shell script to be executed in a .rvmrc file.

Create a file named .ruby-gemset containing only the gemset name in.
Need an up to date version of rvm for this to work.

You can also specify the ruby version by creating a file named .ruby-version containing only the ruby version:

This format also has the advantage of being compatible with rbenv and rbfu.

If you have existing projects using the deprecated .rvmrc, you can convert them to the new format using the command:
rvm rvmrc to .ruby-version

RubyMine Ubuntu


Install RubyMine

  1. Download RubyMine from Source
  2. Unpack the downloaded archive:
    1. tar -xzf RubyMine-X.Y.Z.tar.gz
  3. Goto extracted folder, nevigate to ‘bin’ directory
    1. ./rubymine.sh
  4. Open any project, goto (Tools) -> (Create Desktop Entry)

Change Rubymine Theme

  1. File -> Settings -> Appearance and Behavior -> Appearance

Remove RubyMine

  1. locate rubymine
  2. locate RubyMine
  3. rm -rf ~/.RubyMine


Install Sublime Text 3 Ubuntu


You have to add the PPA to your system, update the local repository index and install the sublime-text-installer:

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

Optional, to remove sublime text, do:
sudo apt-get remove sublime-text-installer

Registration License Key:

Michael Barnes
Single User License
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
93F6323C FD7F7544 3F39C318 D95E6480
FCCC7561 8A4A1741 68FA4223 ADCEDE07
200C25BE DBBC4855 C4CFB774 C5EC138C

Setup Ubuntu Machine


Install Packages

sudo apt-get install -y curl
sudo apt-get install -y build-essential
sudo apt-get install -y bison byacc gperf
sudo apt-get install -y zlib1g-dev
sudo apt-get install -y libreadline5
sudo apt-get install -y libreadline-dev
sudo apt-get install -y libncurses5 libncurses5-dev
sudo apt-get install -y libssl-dev
sudo apt-get install -y autoconf
sudo apt-get install -y libxml2
sudo apt-get install -y libxml2-dev
sudo apt-get install -y libpng12-0
sudo apt-get install -y libpng12-dev
sudo apt-get install -y libgmp3-dev
sudo apt-get install -y sendmail
sudo apt-get install -y libjpeg62-dev
sudo apt-get install -y openssh-server
sudo apt-get install -y gettext
sudo apt-get install -y imagemagick
sudo apt-get install -y graphicsmagick-libmagick-dev-compat

Install and configure GIT

sudo apt-get install git-core

Colored Git
git config –global color.diff auto
git config –global color.status auto
git config –global color.branch auto
git config –global color.interactive auto
git config –global color.ui true
git config –global push.default tracking
git config –global core.autocrlf false
git config –global core.safecrlf false
git config –global core.ignorecase false
git config –global core.excludefile ~/.gitignore
git config –global diff.renames copies

Install and configure Mysql

sudo apt-get install libmysql++-dev
sudo apt-get install -y mysql-server

Install and configure PHP

sudo apt-get install php

Install PHPMyAdmin

sudo apt-get install phpmyadmin

Install Ruby and Gems

sudo apt-get install ruby
sudo apt install ruby-railties

Install Rvm

curl -L https://get.rvm.io | bash -s stable