Skip to content

Instantly share code, notes, and snippets.

@ninabreznik
Last active October 24, 2017 16:37
Show Gist options
  • Save ninabreznik/9f3799df31e66b9010b6403309dce687 to your computer and use it in GitHub Desktop.
Save ninabreznik/9f3799df31e66b9010b6403309dce687 to your computer and use it in GitHub Desktop.
RAILS Cheat Sheet (BACKUP)
RAILS Cheat Sheet!
########################################
Rails Tutorial/Chapter 1
RUN A LOCAL SERVER
$ rails server
CHECK VERSION OF RUBY
$ ruby -v
CHECK VERSION OF RAILS
$ rails -v
CREATE NEW FOLDER
$ mkdir rails_projects
CREATE RAILS APP
$ rails new name_of_the_app
$ rails new name_of_the_app --skip-test-unit (if you need Rspec or some other test suite)
GO TO THE APP FILE
$ cd name_of_the_app
SWITCHING DIRECTORIES
$ cd .. (back)
$ cd Code/Ruby/lessons_Erik (forth)
OPEN A PROJECT IN SUBLIME
$ subl .
OPEN A FILE IN SUBLIME
$ subl README.md
INSTALLING GEMS
$ bundle install
$ bundle update
$ bundle install --without production (prevents local installation of any production gems)
CREATE NEW REPOSITORY
$ git init
ADD FILE TO GIT
$ git add .
$ git add -a -m "Adding all modifications of existing files"
CHECK PENDING CHANGES
$ git status
COMMITING CHANGES
$ git commit -m "Describing changes you've made"
$ git commit -am "Commit all changes and a message"
LIST OF ALL COMMIT MESSAGES
$ git log
LIST ALL THE FILES IN A DIRECTORY
$ ls
$ ls app/controllers
REMOVE DIRECTORY (-rf "recursive force" - removes all files/directories/subdirectories)
$ rm -rf app/controllers
GIT CHECKOUT PREVIOUS COMMIT (-f force, overwriting current changes)
$ git checkout -f
GITHUB - CREATE A REPOSITORY
$ git remote add origin https://github.com/ninabreznik/sample_app.git
GITHUB - COMMIT/PUSH
$ git push -u origin master
$ git push (for regular push)
GIT - CREATE BRANCH
$ git checkout -b name_of_the_branch
GIT - LIST ALL LOCAL BRANCHES
$ git branch
GIT - SWITCH FROM RDoc TO Markdown markup language
$ git mv README.rdoc README.md
GIT - MERGING RESULTS INTO MASTER BRANCH
$ git checkout master
$ git merge name_of_the_branch
GIT - DELETING THE BRANCH
$ git branch -d name_of_the_branch
$ git branch -D name_of_the_branch (delete branch even if we didn't merged in the changes)
GIT - RENAME LAST COMMIT
$ git commit --amend -m “new message"
##################################################
Rails Tutorial/Chapter 2
CREATE NEW APP - STEPS
$ cd ~/rails_projects
$ rails new demo_app
$ cd demo_app
gem file
$ bundle install --without production
$ bundle update
$ bundle install
$ git init
$ git add .
$ git commit -m "Initial commit"
$ git remote add origin https://github.com/<username>/demo_app.git
$ git push -u origin master
SCAFFOLD
$ rails generate scaffold User name:string email:string
MIGRATE/UNDO DATABASE
$ bundle exec db:migrate
$ rake db:migrate
$ rake db:rollback
SCAFFOLD
URL ACTIONS PURPOSE
/users index list all users
/users/1 show show user with id 1
/users/new new make new user
/users/1/edit edit edit user with id 1
INHERITANCE IN CONTROLLERS
controllers: class UsersController < ApplicationController
models: class User < ActiveRecord::Base
ROUTES (config/routes.rb)
resources :controller
(resources :users)
(automaticaly creates routes for CRUD; REST architecture)
root 'static_pages#home'
match '/help', to: 'static_pages#help', via: 'get'
(manually creates routes)
REST ARCHITECTURE (REpresentational State Transfer; modelled as CRUD operations of relational database)
HTTP request URL Action Purpose
GET /users index page to list all users
GET /users/1 show page to show user with id 1
GET /users/new new page to make a new user
POST /users create create a new user
GET /users/1/edit edit page to edit user with id 1
PATCH /users/1 update update user with id 1
DELETE /users/1 destroy delete user with id 1
VALIDATIONS
class Micropost < ActiveRecord::Base
validates :content, length: { maximum: 140}
end
CONSOLE
$ rails console
$ exit
##################################################
Rails Tutorial/Chapter 3
CONFIGURE RSPEC
$ rails generate rspec:install
$ rails generate integration_test static_pages (#creates static_pages_spec.rb and spec/request directory)
INSTALL RSPEC
group :development, :test do
gem 'rspec-rails', '->2.0'
end (copy to Gemfile)
$ bundle install
$ rails generate rspec:install
GENERATE/DESTROY CONTROLLER
$ rails generate controller StaticPages home help --no-test-framework
$ rails generate controller static_pages home help --no-test-framework
$rails destroy controller Static pages home help
GENERATE/DESTROY MODEL
$ rails generate model Foo bar:string baz:integer
$ rails destroy model Foo
RSPEC DOMAIN-SPECIFIC LANGUAGE
DESCRIBE BLOC
describe "home page" do
it "…" do
...
end
end
VISIT
visit '/static_pages/home'
EXPECT
expect(page)to have_content( 'Sample App')
RUN RSPEC TEST
$ bundle exec spec spec/request/static_pages_spec.rb
$ bundle exec spec/spec (run all tests)
HTML DOCUMENT TYPE
<! DOCTYPE html>
EMBEDDED RUBY (ERb)
<% provide(:title, 'Home') %>
<%= yield(:title) %> (executes the code AND inserts result in the template)
##################################################
Rails Tutorial/Chapter 4
STYLESHEET LINK TAG
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %> (include application.css)
USER CLASS
atrr_accessor :name, :email (creates "getter" and "setter" methods; allows us to get and set @name and @email instance variables)
INSTANCE VARIABLES
def initialize
##################################################
Rails Tutorial/Chapter 5
PARTIALS CALLING (partial file _header.html.erb)
<% render 'layouts/header %>'
LAYOUT LINKS
<%= link_to "About", about_path %>
##################################################
Project group / Alex
GIT LOG (to check commit hash)
GIT SHOW paste commit hash
(going back to see changes in previous commit)
GIT STASH
checkout branch_name
GIT STASH POP
(stashing code and pasting it to another branch)
#################################################
git branch
git branch -m microposts (rename local branch)
CONTROLLERS
class UsersController < ApplicationController
before_action: signed_in_user, only: [:edit, :update] #restrict the filter to act only on the :edit and _update actions
# Before filters (take place before controller actions)
def signed_in_user
redirect_to signin_url, notice: "Please sign in." unless signed_in?
end
##################################################
Chapter 11
has many :relationships
has_many :followed_users, through: :relationships, source: :followed
User (has many posts)
Posts (belong to user)
Posts (add migrations (user_id)) => rails g migration name_of_migration (i.e. AddUserIdToPost)
rake db:migrate
generate migration vs. destroy migration (+ rm db/development.sqlite3)
add_column :posts, :user_id, :integer
############
Git meetup
$ GIT reset --hard (returning to previous version; last commit)
GIT fetch ( to see diff and then you merge it)
GIT pull (automatically overwrites your local version)
Git-scm.com/book
##################################################
CREATING TODO LIST
Todo model (Scaffolding)
User model (Devise) - http://guides.railsgirls.com/devise/
Has_many/Belongs_to (foreign key: user_id) - http://ruby.railstutorial.org/chapters/user-microposts?version=3.2#top
Mark Todos as Complete (http://www.codelearn.org/ruby-on-rails-tutorial/rails-migration-form_for-checkbox-example) github: todoapp on my repo
####################################
IKUSEI
RVM USE ruby-1.9.3.-p448 (change versions with RVM)
CMD T (searching through file names in Sublime)
RVM GEMSET LIST (list all special GEMSETS for different projects)
SSH-KEYGEN -T DSA (generating public/private dsa key pair)
GEM LIST (show all gems)
**Shortcuts - ITERM (terminal)
cmd D --> split the screen vertically
cmd shift D --> split the screen horizontally
cmd F in nato cmd D for marking fields we want to rewrite
##############################
Command line (Terminal)
cp ../from/this/path/file to/this/path/file
cp -r ../from/this/path/directory to/this/path/directory
mv (move)
mv -r
mkdir nameofthefolder
touch nameofthefile
rm deletes/path/to/file
rm -rf deletes/path/to/directory
###############################
Installing Rails & Ruby
rvm usage (explains commands)
rvm list known (lists available rubies)
rvm install ruby-1.9.3
rvm use ruby-2.1-head (change ruby to this version -> mannheim)
bundle install (install all the packages you need for this project)
###############################
FORMS
#CAMPAIGN
views/index
<% @campaigns.each do |campaign| %>
<%= campaign.title %>
<% end %>
campaigns_controller
def index
@campaigns = Campaign.all
end
def create
@campaign = current_user.campaigns.create
end
#USER
users_controller
def correct_user
#FOLLOWING/FOLLOWERS relationships
campaign.rb (has_many :coowners, through: :relationships, source: :coowned_id)
$ rails generate model Relationship coowner_id:integer coowned_id:integer
add_index :relationships, [:coowner_id, :coowned_id ], unique: true (migration)
bundle exec rake db:migrate
bundle exec rake test:prepare
Relationship(id, coowner_id, coowned_id, created_at, updated_at)
User (has_many :relationships, foreign_key: “coowner_id”)
Campaign (has_many :relationships, foreign_key: “coowned_id”)
Relationship(belongs_to :coowned, class_name: “Campaign”, belongs_to :coowner, class_name: "User”)
relationships_controller: create, destroy
User.rb: clowning?, coown!, uncoown!
Routes! resources :relationship, only: [:create, :destroy]
#################################################################
Validation Unique
(Campaign.rb)
validates :title, uniqueness: { scope: :location }
##################################################################
INTERNATIONALIZATION
#Locales YAML file
en:
lead:
location: "Region"
zip: "Zip"
time: "Time"
description: "Description"
name: "Name"
address-book-link: "Address book"
#Views:
<%= I18n.t'lead.location' %>
<%= link_to "#{I18n.t'lead.address-book-link'}", orders_path %>
###############################################
Styling STYLUS
create something.styl in app/assets/stylesheets
cd app/assets/stylesheets in terminal and stylus -w something.styl
views/layout/application.html.erb => in head add <link rel="stylesheet" type="text/css" href=“assets/something.css”>
stylus -u jeet -u rupture -u axis -w app/assets/stylesheets/app.styl
stylus -u jeet -u rupture -u axis -w public/app.styl -o app/assets/stylesheets/ -l
(for LeadShareApp)
####################################################
DEPLOYING ZWEIDESIGN
$cap production deploy
Check app
cd ..
cd ..
cd opt/leadshareapp
Current - current app
Shared - log files
$ssh 5.39.51.100 (access to server for Sosed.biz Leadshareapp)
SQL console:
ninabreznik@vps105:/opt/leadshareapp/current/db$ sqlite3 /opt/leadshareapp/current/db/production.sqlite3
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
active_admin_comments orders users
admin_users paypal_notifications
leads schema_migrations
sqlite> .schema users
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255) DEFAULT '' NOT NULL, "encrypted_password" varchar(255) DEFAULT '' NOT NULL, "reset_password_token" varchar(255), "reset_password_sent_at" datetime, "remember_created_at" datetime, "sign_in_count" integer DEFAULT 0 NOT NULL, "current_sign_in_at" datetime, "last_sign_in_at" datetime, "current_sign_in_ip" varchar(255), "last_sign_in_ip" varchar(255), "created_at" datetime, "updated_at" datetime, "wallet" integer DEFAULT 0);
CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email");
CREATE UNIQUE INDEX "index_users_on_reset_password_token" ON "users" ("reset_password_token");
sqlite>
RAKE TASKS in PRODUCTION
bundle exec rake users: RAILS_ENV=production
heroku run rake users:name_of_the_task
LOCALLY
rake users:name_of_the_task
####################################################
JS hacks for social media clicks
Twitter (FOLLOW)
for(var i=0,a=document.querySelectorAll(".not-following .js-follow-btn"); i<a.length;i++){a[i].click();}
Linkedin(FOLLOW)
for(var i=0,a=document.querySelectorAll(".bt-request-buffed"); i<a.length;i++){a[i].click();}
Pinterest (Follow)
for(var i=0,a=document.querySelectorAll(".FollowButton"); i<a.length;i++){a[i].click();}
Manageflitter
for(var i=0,a=document.querySelectorAll(".Unfollow"); i<a.length;i++){a[i].click();}
####################################################
WITH MARC
Mailers
Check mails http://0.0.0.0:3000/rails/mailers
Rake tasks
rake -T (list of all rake tasks) => then you run this command
LIB/TASKS (create new task)
RAKE TASKS in PRODUCTION
bundle exec rake users:send_first_message RAILS_ENV=production
####################################################
HEROKU
heroku logs
heroku run console
git push heroku
heroku run rake db:migrate
####################################################
"gem install reek" and then reek project folder
KILL RAILS SERVER
ps aux | grep rails
kill -9 <number of process>
####################################################
PHOTOS IMAGES RESIZING APPEND IMAGEMAGIC
from the images folder
type in terminal:
convert -resize 33% obvestilo_3.png obvestilo_3a.png
###################################################
$ssh 5.39.51.100 (access to server for Sosed.biz Leadshareapp)
Delete and copy PUBLIC/SYSTEM folder from backup
rm -rf /opt/backup_leadshareapp/system
cp -r /opt/leadshareapp/current/public/system /opt/backup_leadshareapp/
(bundle exec) cap production deploy # in another tab
rm -rf /opt/leadshareapp/current/public/system
cp -r /opt/backup_leadshareapp/system/ /opt/leadshareapp/current/public/
###################################################
IN CURRENT
if columns duplicate (not equal in production and development)
bundle exec rake db:migrate RAILS_ENV=production
cd /opt/leadshareapp/current/
RAILS_ENV=production bundle exec rails c
###################################################
ifconfig (to get ip address for localhost)
###################################################
API
routes:
match '/api/lesson5', to: 'projects#projectxx', via: 'get'
match '/api/lesson4', to: 'projects#postxx', via: ‘post'
controller:
@project = Project.last
render :json => @project.as_json(:only => [:title])
end
def postxx
render json: request.body.read
end
********** ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************
D O C K E R
##################
1 LOCAL
##################
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CREATE APP
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ rails new sample_app
$ cd sample_app
$ rake db:migrate
#Edit Gemfile
group :production do
gem 'pg'
end
group :development do
gem 'sqlite3'
end
group :test do
gem 'sqlite3'
end
$ gem install pg
$ bundle install
$ export RAILS_ENV=development
$ rails generate controller StaticPages hello
#Modify routes.rb
root 'static_pages#hello’
$ rake db:migrate
#Edit database.yml
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: postgresql
pool: 5
timeout: 5000
username: postgres
password:
database: ninabreznik_test
encoding: utf8
production:
adapter: postgresql
pool: 5
timeout: 5000
username: postgres
password:
host: <%= ENV['DB_PORT_5432_TCP_ADDR'] %>
database: esova-production
encoding: utf8
$ export RAILS_ENV=development
$ rake db:setup db:create
$ rails s
###########################
2 DOCKERIZE THE APP
###########################
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CREATE DOCKER MACHINE DEFAULT
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ docker-machine create -d virtualbox default
$ export DB_PORT_5432_TCP_ADDR=$(docker-machine ip default)
$ eval $(docker-machine env default)
## Create Dockerfile in sample_app/Dockerfile
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
FROM ruby:2.2.0
RUN apt-get update -qq && apt-get install -y build-essential
#for postgres
RUN apt-get install -y libpq-dev
#for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev nodejs
ENV APP_HOME /app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile* $APP_HOME/
RUN bundle install --jobs=4
RUN test -f $APP_HOME/tmp/pids/server.pid && rf $APP_HOME/tmp/pids/server.pid; true
ADD . $APP_HOME/
CMD bin/rails server --port 3000 --binding 0.0.0.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
##Create secrets.yml
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
development:
secret_key_base: 389f9a898fa1f06ce656d614b8c630b134042806fd3c648bb9ad44a6006cdc009c49acb06db02e5cf9953de9331ff7375165630d1f28dfbd091c0251269b48a6
test:
secret_key_base: 389f9a898fa1f06ce656d614b8c630b134042806fd3c648bb9ad44a6006cdc009c49acb06db02e5cf9953de9331ff7375165630d1f28dfbd091c0251269b49b3
production:
secret_key_base: 389f9a898fa1f06ce656d614b8c630b134042806fd3c648bb9ad44a6006cdc009c49acb06db02e5cf9953de9331ff7375165630d1f28dfbd091c0251269b49b3
secret_token: 7329283424nj4n
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
BUILD A DOCKER IMAGE
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ docker build -t esova .
$ docker tag -f esova ninabreznik/esova:latest
$ docker run -d -p 5432:5432 --name db postgres
$ docker run -d --name dev-app -v `pwd`:/app -p 80:3000 --link db:db ninabreznik/esova
(mounting your current working directory inside of docker container - `pwd` to wherever my app is running) - careful with back ticks when you copy in terminal!
###########################
3 DOCKER HUB
###########################
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TAG AN APP, CREATE REPO AND PUSH
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ docker login
$ docker tag testapp1 ninabreznik/esova:latest
$ docker push ninabreznik/esova
###########################
3 DIGITAL OCEAN
###########################
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CREATE DROPLET
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Go to Digital Ocean and under API create a token
$ docker-machine create --driver digitalocean --digitalocean-access-token=3e9304093aa715d79894f4d8e15424ce9a3cbdae33ca722e92f4661ebf78db82 esova
$ export DB_PORT_5432_TCP_ADDR=$(docker-machine ip esova)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
PULL AND RUN IMAGE IN PRODUCTION
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ s
$ docker pull ninabreznik/esova
$ docker pull postgres
$ docker create -v /var/lib/postgresql/data --name dbdata postgres bin/true
$ docker run -d -p 5432:5432 --volumes-from dbdata --name esova-production -e POSTGRES_PASSWORD="" postgres
$ export DB_PORT_5432_TCP_ADDR=$(docker-machine ip esova)
$ rake db:create
$ rake db:migrate
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app da2c6c42f610
###########################
4 UPDATE APP
###########################
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
UPDATE
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Save app locally
$ eval $(docker-machine env default)
$ cd /Users/ninabreznik/Code/eSova/esova
$ docker build -t esova .
$ docker tag -f image_id ninabreznik/esova
$ docker push ninabreznik/esova
$ eval $(docker-machine env esova)
$ docker pull ninabreznik/esova
$ docker rm -f run-app
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app da2c6c42f610 (esova image id)
IF MIGRATIONS
$ docker run image_id rake db:migrate
$ docker commit container_id
$ docker images
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app new_image_id
$ docker rm -f run-app
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app da2c6c42f610 (esova image id)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DIGITAL OCEAN
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ eval $(docker-machine env esova)
$ docker pull ninabreznik/esova
$ docker rm -f run-app
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app
da2c6c42f610
MIGRATIONS!
**
$ docker run image_id rake db:migrate
$ docker ps -a # find container_id that includes migrations e.g. d81f6c4b0aa2 572c3c473062 "rake db:migrate" 7 minutes ago Exited (0) 7 minutes ago ….)
$ docker commit container_id
$ docker images (??)
$ docker tag New_Image_Id ninabreznik/esova (??)
I think migrations are necessary, then commit, but after that you run your pulled image again! So these 2 lines instead the previous one.
$ docker rm -f run-app
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app image_id
**
$ docker run -d -p 80:3000 -e RAILS_ENV=production --link esova-production:db --name run-app da2c6c42f610
************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************
DOCKER COMMANDS
#Docker Run
$ docker run -d -P --name web nginx # Starts new Nginx container (it points by default to the docker_host)
$ docker run --name some-rails-app -d my-rails-app #run docker image
$ docker run -it ninabreznik/esova # entering docker container
$ docker-machine ls #lists available machines
$ docker ps # displays your running container (nginx)
$ docker ps -a # displays all your containers
$ docker images # display images
$ docker port web # shows container ports (web container’s port is 80
$ docker-machine ip default # get ip for default
$ docker start 8a55b698db20 # start running nginx container
$ docker stop 8a55b698db20 # stop running nginx container
$ docker rm 8a55b698db20 # remove a container
$ docker port web # view container ports (web container’s port 80)
$ docker-machine ip default # gets the address of default VM
$ docker inspect container or image # see details about certain image/container
$ eval $(docker-machine env esova)
$ docker exec -it run-app /bin/bash #BASH INTO THE APP
$ rails c
# RUN THE CONSOLE IN PRODUCTION
$ docker-machine restart default # Restart the environment
$ eval $(docker-machine env default) # Refresh your environment settings
$ docker start db
$ docker-machine ssh default # ssh to your docker machine
$ docker-machine help
$ docker help
$ docker-machine rm dev #remove certain docker machine
$ docker build -t my-rails-app . #build docker image
$ docker-machine ip default # get container ip address
$ docker rm -f container_id
$ docker rmi -f image_id
$ docker rm $(docker ps -a -q) #remove all stopped containers
$ docker rmi $(docker images -f "dangling=true" -q) # remove unused images
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Automating Docker - Docker Compose
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Create docker-compose.yml file
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
db:
image: postgres
ports:
- "5432:5432"
web:
build: .
command: bin/rails server --port 3000 --binding 0.0.0.0
ports:
- "3000:3000"
links:
- db
volumes:
- .:/myapp
$ docker-compose build
$ docker-compose up
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DEBUGGING WITH Michelle
$ Rails.application.secrets # check secrets in the console
$ tail -F log/production.log
$ sudo chown -R ninabreznik:staff . # chown - change ownership; -R recursive,
Postgres
esova-production
password: “"
$ eval $(docker-machine env esova)
$ docker logs run-app # LOGS in PRODUCTION
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MONITORING
$ top # see all running processes on the computer
$ top -o men # sort all processes by memory usage
DOCKER
$ docker stats run-app #see all the processes running in the container
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
JANNIS
$ wget -r --no-parent http://192.168.3.67:8080/moderat/ #download everything that is on this url)
$ python -m SimpleHTTPServer #run simple http server (cd to folder you want to share - people can go on Nina.local:8000 and access it
$ youtube-dl --audio-format mp3 --yes-playlist -f 141 '<youtube-video-in-playlist-url-hier>’ #download stuff from youtube (you need before brew install youtube-dl)
Time Machine - Backup
Software for RaspberryPi https://www.bananian.org/
Backup server https://gist.github.com/derhuerst/e1d30e03729a9210e604ef2166825247
Create ReadOnlyUser to share files over SFTP (basically SSH)
Janiss Server
Lookup
ssh [email protected] -p 30020
pass:schlupf and dudel
cd /Volumes/Medien
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Require Bin hack
var iframe = document.querySelector('iframe')
var parent = iframe.parentElement
parent.removeChild(iframe)
iframe.setAttribute('scrolling', 'yes')
parent.appendChild(iframe)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
PHONEGAP
http://docs.phonegap.com/getting-started/
myApp/www
//myApp/www/Index.js
document.addEventListener('deviceready', function(){
var script = document.createElement('script')
script.src='bundle.js'
document.body.appendChild(script)
}, false);
//myApp/www/Index.html
<body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
quiz
package.json
add to “scripts"
"release": "browserify index.js -o bundle.js -t [ babelify --presets [ es2015 ] ]”
$ npm install --save-dev babelify (https://github.com/babel/babelify)
$ npm install --save-dev babel-preset-es2015
$ npm run release
$ cp quiz/bundle.js myApp/www/bundle.js
$ phone gap serve
///
$ phonegap platform add iOS
////
JANNIS
Downloading from the internet to the file
curl https://fonts.gstatic.com/s/baloochettan/v1/ODsFofLybGVOJ90e_EwdFW2C_mZLXxrZg-qBMMega1s.woff2 > baloochettan-latin.woff2
@teo251
Copy link

teo251 commented May 4, 2016

extra...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment