Skip to content

Instantly share code, notes, and snippets.

@lumen-us
lumen-us / rails_starter_app.md
Last active April 22, 2018 20:57
New Rails 5.1 App on Cloud9 IDE (starter app guide)

Новое rails 5.1 приложение на c9.io (blank Ubuntu workspace)

1. Настройки RVM

$ rvm get stable --autolibs=enable            # upgrades to latest stable version
$ rvm list known                              # list all known ruby versions
$ rvm install 2.4.1                           # install latest ruby version
$ rvm use --default 2.4.1

2. Copy this to .bash_aliases on c9.io

@lumen-us
lumen-us / digitalocean.md
Last active May 1, 2017 14:27
digitalocean: one droplet - multiple domains

Размещение нескольких ruby on rails приложений на одном дроплете Digitalocean

  1. Деплоим приложение как обычно с помощью Capistrano
  2. Настраиваем доменное имя на digitalocean, туториал
  3. Добавляем строку в файле /home/etc/hosts с доменным именем
# /home/etc/hosts
...
127.0.0.1 pinshop.com.ua www.pinshop.com.ua
...
@lumen-us
lumen-us / ubuntu.md
Last active August 28, 2017 20:21
Useful commands for Ubuntu

1. Get a human-readable ascending list of the sizes of files and subdirectories in your current directory (-sh will sumarize the current directory size)

$ du -sh * | sort -h

2. Check Ubuntu version

$ lsb_release -a
@lumen-us
lumen-us / rails.md
Created April 3, 2017 07:45
Use mailcatcher to view emails in development mode

Use mailcatcher to view emails in development mode

Please don't put MailCatcher in your Gemfile. It is an application in its own right with its own dependencies that can't possibly interoperates with every version of rails. Simply:

gem install mailcatcher
mailcatcher

and it will be accessible at http://127.0.0.1:1080/

@lumen-us
lumen-us / rails.md
Created March 17, 2017 15:41
rails ajax example

Ruby on Rails Ajax example

  1. Add remote: true option to link, button or form
# app/views/products/show.html.haml

button_to 'Add to Cart', line_items_path(product_id: product), remote: true
  1. Stop the create action from redirecting to the index display if the request is for JavaScript. We do this by adding a call to respond_to() telling it that we want to respond with a format of .js:
@lumen-us
lumen-us / rails.md
Last active February 14, 2017 15:25
Create new rails project with onotole gem

Create new rails project with [onotole][1] gem on [c9.io][2]

1.Create new hosted workspace with 'Ruby' template on [c9.io][2]

  1. Install gem [onotole][1]

$ gem install onotole
@lumen-us
lumen-us / index.md
Created December 19, 2016 14:23 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@lumen-us
lumen-us / remove_lines_from_file.md
Last active December 7, 2016 14:50
Remove lines from file on regex match

How to remove lines from file on regex match in ruby

# remove_comment_lines_from_haml_file.rb
require 'fileutils'

open('file.html.haml', 'r') do |f|
  open('file.html.haml.tmp', 'w') do |f2|
    f.each_line do |line|
 f2.write(line) unless line =~ /^\s+\/.*$/ # regex for comments in haml template
@lumen-us
lumen-us / git.md
Last active November 15, 2016 14:11
How to merge a specific commit in git

How to merge a specific commit in git

Scenario

You were working on a certain branch of a git repository, and you committed some changes to it. Then you realize, this particular commit should also go to another branch of the repository BUT you are not ready for a complete merge. Maybe this commit was meant for the other branch?

You want to merge this particular commit from the current branch to the other branch of your requirement.

Solution