Skip to content

Instantly share code, notes, and snippets.

View rutvij-pandya's full-sized avatar

Rutvij Pandya rutvij-pandya

View GitHub Profile
@rutvij-pandya
rutvij-pandya / secure_random.rb
Created October 12, 2018 10:28
Generate random alphanumeric string in Ruby (v < 2.5)
# Ruby(2.4.4) Module - SecureRandom - https://ruby-doc.org/stdlib-2.4.4/libdoc/securerandom/rdoc/SecureRandom.html
SecureRandom.class_eval do
CHARSET = [*"A".."Z", *"0".."9"]
# Returns Randomly generated 6 or more char long alphanumeric string
def self.alphanumeric(number)
CHARSET.sample(number).join
end
end
@rutvij-pandya
rutvij-pandya / enable-query-stats.rb
Last active May 8, 2018 13:23
Steps to enable query stats in pgHero dashboard
## Modify postgresql.conf
# Find postgresql.conf
# ---- For mac users ----
cd /usr/local/var/postgres/
vi postgresql.conf
# ---- For ubuntu users ----
cd /etc/postgresql/<version>/main
@rutvij-pandya
rutvij-pandya / integrate_pg_hero.rb
Last active May 1, 2018 11:39
Steps to integrate pgHero with Rails
## Gemfile
gem 'pghero'
# pg_query is used by pghero to provide suggestions to add indexes
gem 'pg_query', '>= 0.9.0'
# bundle install
## Add a route to access the pgHero Dashboard
# You can secure its access with Devise user authentication
# CentOS 6.5
Install rvm
>> curl -L get.rvm.io | bash -s stable
>> \curl -sSL https://get.rvm.io | bash
>> source /etc/profile.d/rvm.sh
>> rvm reload
Install Ruby
>> rvm install 2.1.2
Create new Volume (i.e, 30gb) from Panel
>> Select volume, Go to Actions/Attach
>> Select instance to attach it
Mount volume to /mnt
>> Create EBS volume.
>> Attach EBS volume to /dev/sdf (EC2's external name for this particular device number).
>> Format file system /dev/xvdf (Ubuntu's internal name for this particular device number):
>> sudo mkfs.ext4 /dev/xvdf
>> Only format the file system if this is a new volume with no data on it. Formatting will make it difficult or impossible to retrieve any data that was on this volume previously.
@rutvij-pandya
rutvij-pandya / AWS Part 5-Launch EC2 instance
Created June 6, 2016 07:20
AWS Part 5-Launch EC2 instance and Basic Configuration
Launch EC2 instance
>> Reference - http://dennissuratna.com/rails-deployment-aws2/
Config Security group
Make server private - only accessible via NAT
>> Select Subnat option while configuring instance
Map DNS - link web address - www.foo.com
Basic Configuration for EC2 instance
>> yum -y update
>> yum groupinstall -y 'development tools'
@rutvij-pandya
rutvij-pandya / AWS Part 4-VPC, Subnet, NAT instance
Created June 6, 2016 07:17
AWS Part 4-VPC, Subnet, NAT instance
VPC and subnet
>> Reference - http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Introduction.html
Config VPC - Config Subnet & associate with VPC
>> Reference - http://docs.aws.amazon.com/AmazonVPC/latest/GettingStartedGuide/getting-started-create-vpc.html
NAT (Network Access Translation) instance
>> Reference - http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_NAT_Instance.html
Config NAT server
>> Reference - http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_NAT_Instance.html#NATInstance
Define Routing in Subnet
@rutvij-pandya
rutvij-pandya / AWS Part 3-Server Aliasing
Created June 6, 2016 07:13
AWS Part 3-Server Aliasing
Open bash_profile file
>> vi ~/.bash_profile
Add Alias in bash_profile file
>> alias ssh-nat="ssh -i ~/.ssh/key-pair.pem ec2-user@1.1.1.1" # Replace with actual server ip
Save
>> :wq
Refresh file
>> source ~/.bash_profile
Try Alias
>> ssh-nat
@rutvij-pandya
rutvij-pandya / AWS Part 2-Add Key to NAT or App instance
Created June 6, 2016 07:12
AWS Part 2-Add Key to NAT/App instance
Each server has .ssh/authorized_keys file
Each SSH key has Private & Public key
Copy content within Pub key of relevant Private key & paste it in relevant server's .ssh/authorized_keys file
>> vi .ssh/test_ssh.pub
>> Copy content
>> ssh-nat (alias)
>> ssh-learn (alias)
>> vi .ssh/authorized_keys
>> i - Paste content
>> :wq - save
@rutvij-pandya
rutvij-pandya / AWS Part 1-SSH Key generation.txt
Last active June 6, 2016 07:09
AWS Part 1 - SSH Key generation
# First step to AWS - learn to generate SSH key for servers
Generate Key in Mac
>> ssh-keygen
Give path & key name
>> Enter file in which to save the key (/Users/username/.ssh/id_rsa): /Users/username/.ssh/test_ssh
Enter password (optional)
>> Enter passphrase (empty for no passphrase):
>> Enter same passphrase again:
"Your identification has been saved in /Users/username/.ssh/test_ssh.