Skip to content

Instantly share code, notes, and snippets.

View pvin's full-sized avatar

praaveen vr pvin

View GitHub Profile
@pvin
pvin / gist:51af0fdb9a7793faf1a6e82fe1c2f457
Last active January 26, 2018 12:04
rbenv installation
You first need to uninstall the ruby installed by Ubuntu with something like sudo apt-get remove ruby.
Then reinstall ruby using rbenv and ruby-build according to their docs:
cd $HOME
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
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
systemctl status mssql-server
@pvin
pvin / gist:43f9dc283e04619ddf3d3d446db46e79
Last active December 22, 2017 07:10
base64 Encoding and Decoding for mp4 ruby
Encoding
require 'base64'
data = File.open('/home/name/folder/sample-video.mp4').read
encoded = Base64.encode64(data)
Decoding
File.open("/home/name/received/sample.mp4", "wb") do |file|
 file.write(Base64.decode64(encoded))
a. gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
b. cd /tmp
c. curl -sSL https://get.rvm.io -o rvm.sh
d. cat /tmp/rvm.sh | bash -s stable --rails
e. source /home/username/.rvm/scripts/rvm
@pvin
pvin / gist:4ff1a64da96852683c6541daf8c45bd5
Created December 7, 2017 16:04
Backup and Restore a database of mssql
sqlcmd -S localhost -U SA -Q "BACKUP DATABASE web_ilids_development TO DISK = N'/var/opt/mssql/data/web_ilids_development.bak' WITH NOFORMAT, NOINIT, NAME = 'web_ilids_development-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-backup-and-restore-database
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools#ubuntu
@pvin
pvin / gist:86f8cc560d4098adf54482a10ea7c798
Last active December 3, 2017 12:28
How to run the rails 5 application in production mode?
Change in config/environments/production.rb
config.assets.compile = true
Change in config/initializers/devise.rb
config.secret_key = '34790ca67ba55291b876053e2de5a248059345fd3994ada01bc4f16a4b272dedcffdee6c71f9a4b3a92773462686c9ee4a0753b02efcc26d14e6ee11cb9fc9c6'
Change in config/secrets.yml
secret_key_base: 32790ca67ba55234b876053e2de5a248059345fd3994ada01bc4f16a4b272dedcffdee6c71f9a4b3a92773462686c9ee4a0753b02efcc26d14e6ee11cb9fc9c6
Configure database.yml with production env
begin
ActiveRecord::Base.transaction do
User.create(name: 'test')
Role.create(name:'manager')
end
rescue => e
raise ActiveRecord::Rollback
end
@pvin
pvin / gist:51b55937e979ccf09d358d26c88c215d
Created October 19, 2017 10:35
ufw for blocking the ports
Connect to Server(ssh)
sudo apt-get install ufw
sudo ufw allow 80 (port http)
sudo ufw allow 443 (port https)
sudo ufw allow 22 (port SSH)
sudo ufw enable
sudo ufw reload
sudo ufw status (will list all open ports)
@pvin
pvin / psql_reference.txt
Last active January 31, 2018 11:30
psql
login with peer authondication
sudo -u postgres psql
login with md5
Then type:
sudo -u postgres psql
Then:
Rspec::
rspec
rspec spec/models
rspec spec/controllers/accounts_controller_spec.rb
rails generate rspec:model
/factories /support /models /controllers /features /views /mailers /routing /helpers
Model spec - behavior of model
require "rails_helper"