http://guides.rubyonrails.org/migrations.html
- add_column
- add_index
- change_column
- change_table
- create_table
- drop_table
| class ApplicationController < ActionController::Base | |
| # Catch all exceptions at a stretch | |
| rescue_from Exception, :with => :handle_exceptions | |
| private | |
| # Handle exceptions | |
| def handle_exceptions(e) | |
| case e |
| # config/routes.rb | |
| resources :documents do | |
| scope module: 'documents' do | |
| resources :versions do | |
| post :restore, on: :member | |
| end | |
| resource :lock | |
| end | |
| end |
| require 'openssl' | |
| class String | |
| def encrypt(key) | |
| cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC').encrypt | |
| cipher.key = Digest::SHA1.hexdigest key | |
| s = cipher.update(self) + cipher.final | |
| s.unpack('H*')[0].upcase | |
| end |
| class API::V1::BaseController < ApplicationController | |
| skip_before_filter :verify_authenticity_token | |
| before_filter :cors_preflight_check | |
| after_filter :cors_set_access_control_headers | |
| def cors_set_access_control_headers | |
| headers['Access-Control-Allow-Origin'] = '*' | |
| headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS' |
http://guides.rubyonrails.org/migrations.html
| # to generate your dhparam.pem file, run in the terminal | |
| openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
| # Assumes the database container is named 'db' | |
| DOCKER_DB_NAME="$(docker-compose ps -q db)" | |
| DB_HOSTNAME=db | |
| DB_USER=postgres | |
| LOCAL_DUMP_PATH="path/to/local.dump" | |
| docker-compose up -d db | |
| docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}" | |
| docker-compose stop db |
| Backup: | |
| docker exec -t -u postgres your-db-container pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql | |
| Restore: | |
| cat your_dump.sql | docker exec -i your-db-container psql -Upostgres |
| #!/usr/bin/env ruby | |
| ADDED_OR_MODIFIED = /^\s*(A|AM|M)/.freeze | |
| changed_files = `git status --porcelain`.split(/\n/) | |
| unstaged_files = `git ls-files -m`.split(/\n/) | |
| changed_files = changed_files.select { |f| f =~ ADDED_OR_MODIFIED } | |
| changed_files = changed_files.map { |f| f.split(" ")[1] } |
| #!/usr/bin/env ruby | |
| # | |
| # = Email Ping | |
| # | |
| # Check to see if an email address exists by looking up MX records and connecting | |
| # to the address's home SMTP server. It then starts to send a message to the address | |
| # but quits before the message is actually sent. | |
| require 'resolv' | |
| require 'net/smtp' |