As configured in my dotfiles.
start new:
tmux
start new with session name:
| # lib/tasks/db.rake | |
| namespace :db do | |
| desc "Dumps the database to db/APP_NAME.dump" | |
| task :dump => :environment do | |
| cmd = nil | |
| with_config do |app, host, db, user| | |
| cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump" | |
| end | |
| puts cmd |
| ```sudo -H pip install zope.interface -U``` | |
| ```sudo -H pip install certbot -U``` | |
| ```wget https://dl.eff.org/certbot-auto``` | |
| ```chmod a+x certbot-auto``` | |
| ```sudo ./certbot-auto certonly --standalone -d agilelab.sg www.agilelab.sg --debug``` | |
| Set up Nginx to serve SSL | |
| ``` | |
| upstream futureworkz { |
| ```sudo -H pip install zope.interface -U``` | |
| ```sudo -H pip install certbot -U``` | |
| ```certbot-auto certonly --standalone -d agilelab.sg www.agilelab.sg --debug``` | |
| Set up Nginx to serve SSL | |
| ``` | |
| upstream futureworkz { | |
| server unix:///home/futureworkz/production/shared/tmp/futureworkz.sock; | |
| } |
| Rendering JSON: Active Model Serializer Vs JBuilder | |
| - AMS: seperate its own serialization concerns into seperate folders, files, OOP | |
| - JBuilder: view extension, use along with html version (eg: show.html.slim and show.jbuilder) | |
| So, if full api, use AMS, if have api and views, use jbuilder natively or ASM | |
| ASM is OOP approach -> choose this 1 as personal |
| User `constraints` to specify the subdomain name for api portion and can introduce load balancing or increase number of api server needed based on its usage. | |
| ```ruby | |
| Rails.application.routes.draw do | |
| namespace :api, path: '/', constraints: { subdomain: 'api' } do | |
| resources :users | |
| end | |
| end | |
| ``` |
| require 'net/http' | |
| require 'json' | |
| url = 'http://jsonplaceholder.typicode.com/posts/1' | |
| uri = URI(url) | |
| response = Net::HTTP.get(uri) | |
| standard = JSON.parse(response) # keys are string | |
| symbol = JSON.parse(response, symbolize_names: true) # keys are symbols | |
| struct = JSON.parse(response, object_class: OpenStruct) # make resonse become an object, can use struct.id |
| 1. Install Linux updates, set time zones, followed by GCC and Make | |
| sudo yum -y update | |
| sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \ | |
| /etc/localtime | |
| sudo yum -y install gcc make | |
| 2. Download, Untar and Make Redis 2.8 (check here http://redis.io/download) |
As configured in my dotfiles.
start new:
tmux
start new with session name:
| for host in `aws ec2 describe-instances --region us-east-1 | grep PublicIpAddress | cut -d "\"" -f4` ; do ssh -i ~/.ssh/keypairs/dev-gamma-keypair.pem ec2-user@$host -t -o StrictHostKeyChecking=no 'sudo rpm -Uvh https://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm ; sudo yum -y install newrelic-sysmond ; sudo nrsysmond-config --set license_key=dfc748af2b5d0a493659d3a443a7bc2fdbe06fa1 ; sudo /etc/init.d/newrelic-sysmond start' ; done |
| 1. Create db | |
| ```shell | |
| createuser --createdb --login -P <database_name> | |
| --createdb tells Postgres that our user should be able to create databases | |
| --login switch will allow our user to log in to the database | |
| -P means we want to set our new user’s password right now | |
| ``` |