Cheat Sheet Journey

Curl

start with installing curl

sudo apt install curl

Nodejs

sudo apt-get update curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get install -y nodejs

Yarn

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt update && sudo apt install yarn

Rails

Installing Rails Using RVM

apt install gpg-agent gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

if not working try this

gpg2 --keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \curl -L https://get.rvm.io | bash -s stable

We need to run the source command, I think it's depending on the location of the rvm

last time I checked this one worked

source /usr/local/rvm/scripts/rvm

before, I used to use this one, just in case the first one didn't work.

source ~/.rvm/scripts/rvm

check if it was installed properly

rvm --version

continue with the commands below

sudo apt install ruby-railties sudo apt-get install ruby-dev rvm requirements

Ruby

rvm install ruby

Check what ruby versions are installed

rvm list known

install specific version of ruby

rvm install 2.1.1

switch ruby version

rvm use 2.1.1

switch ruby version and set to default

rvm --default use 2.1.1 gem install rails

Install bundler

gem install bundler

if you're having issue with bundler version you can uninstall your current version

gem uninstall bundler

and you can install specific version of bundler

gem install bundler -v '= 1.14.5'

Install rails

Install specific version of rails

gem install rails --version 4.2.5.2

Install specific version of rails without documentation

gem install rails --version 4.2.5.2 --no-ri --no-rdoc

Create rails app

Create specific version of rails app

rails _4.2.5.2_ new app

Rails Production

open the credentials file

EDITOR=nano bin/rails credentials:edit

if you want to set nano as a default editor

export EDITOR=nano export VISUAL=nano

then reload

source ~/.bashrc

btw, printenv it the command to show all env variables

printenv

that way you can run the command like that

bin/rails credentials:edit

if you get error message when trying to open the credentials file, you can delete this file

rm config/credentials.yml.enc

then generate a new one

EDITOR=nano bin/rails credentials:edit

Run migration

RAILS_ENV=production rake db:migrate

Precompiling assets

bundle exec rake assets:precompile

Restart Nginx

sudo service nginx restart

Restart Unicorn

sudo service unicorn restart

if rails console isn't working

rake rails:update:bin

Ruby

install specific version of ruby

rvm install 2.3.1

use specific version of ruby

rvm use 2.3.1 --default

Installing MySQL

sudo apt-get update sudo apt-get install mysql-server sudo mysql_secure_installation sudo apt-get install libmysqlclient-dev

Creating new user

CREATE USER 'username'@'localhost' IDENTIFIED BY '123'; GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost'; FLUSH PRIVILEGES;

Installing Lamp

if Ubuntu 16.04

sudo apt-get install apache2 sudo apt-get install php

or

sudo apt-get install libapache2-mod-php php

for some other version

sudo apt-get install apache2 sudo apt-get install mysql-server sudo apt-get install php5 libapache2-mod-php5

and now restart apache

sudo /etc/init.d/apache2 restart

if still not working try this

sudo apt-get install php-mysql

IPv6

IP information

ip a

disable IPv6

net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1

change the value to 0 to enable IPv6

Git

Start a project

push your project to a repository

git init git remote add origin [repo_link] git add . git commit -m "Init" git push origin master

Branch

list branches

git branch

create new branch

git branch [branch_name]

switch to branch

git checkout [branch_name]

create new branch and switch in one command

git checkout -b [branch_name]

delete branch

git branch -d [branch_name]

show all branches starting with the word "adding"

git branch --list "adding*"

Log

log the changed files

git log --name-only

log the changes in a specific file

git log -p -- filename

log by author

git log --author "Name"

see deleted files

git log --diff-filter=D --summary

Stash

stash and label it "title"

git stash save "title"

show all stashes

git stash list

take back a specific stash form the list (stash@{0})

git stash apply stash@{0}

take back the latest stash

git stash pop

show changes in stash without applying

git stash show -p stash@{0}

show files changed in stash without applying

git stash show -p stash@{0} --name-only

show specific file on a specific commit

git show 54f0cb88:path/to/file

Diff

compare between 2 commits

git diff a32d9ba..c12da8b

compare specific file between 2 commits

git diff a32d9ba..c12da8b -- myfile.js

compare between stash and branch

git diff stash@{0} master

compare changed files between stash and branch

git diff --name-only stash@{0} master

Clone with SSH

check for ssh key if you have one already on your machine

cat ~/.ssh/id_rsa.pub

generate new ssh key

ssh-keygen -t rsa -b 4096 -C "email@example.com"

clone the repository

git clone [repo_link] [folder_name]

if cloning the SSH repo still not working even after you added access with your SSH key, try this command

ssh-add

Users

create new user

sudo adduser valentina

add sudo permissions

sudo usermod -aG sudo valentina

switch user

su - valentina

change password of root user

sudo passwd root

Nginx Passenger

Step 1

install our PGP key and add HTTPS support for APT

sudo apt-get install -y dirmngr gnupg sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7 sudo apt-get install -y apt-transport-https ca-certificates

add our APT repository

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list' sudo apt-get update

install Passenger + Nginx

sudo apt-get install -y nginx-extras passenger

Step 2

edit /etc/nginx/nginx.conf and uncomment include /etc/nginx/passenger.conf; if it's not there simply add it

include /etc/nginx/passenger.conf;

edit /etc/nginx/sites-enabled/default

sudo nano /etc/nginx/sites-enabled/default

replace all you have on this file with that

lastly, configure passenger paths, edit this file /etc/nginx/passenger.conf

sudo nano /etc/nginx/passenger.conf

add those 2 lines

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; passenger_ruby /usr/local/rvm/gems/ruby-2.3.1/wrappers/ruby;

Other

set password for another user (not root), in this example the user is rails

passwd rails

add this user to the sudo group

adduser rails sudo