Skip to content

Instantly share code, notes, and snippets.

View leemour's full-sized avatar

Viacheslav Ptsarev leemour

View GitHub Profile
@leemour
leemour / Padrino DB Postrges
Created April 6, 2013 13:58
Changing defaults in :production from sqlite to pg
#=> config/database.rb
postgres = URI.parse(ENV['DATABASE_URL'] || '')
ActiveRecord::Base.configurations[:production] = {
:adapter => 'postgresql',
:encoding => 'utf8',
:database => postgres.path[1..-1],
:username => postgres.user,
:password => postgres.password,
:host => postgres.host
@leemour
leemour / Console Table Info
Last active December 15, 2015 21:29
Rails/Padrino pretty output of a SQL table Information
puts ActiveRecord::Base.connection.execute("PRAGMA table_info('pages')").to_yaml
puts ActiveRecord::Base.connection.execute("PRAGMA encoding").to_yaml
@leemour
leemour / Gemfile
Created April 18, 2013 08:50 — forked from datenimperator/Gemfile
Sinatra, sprockets, compass, bootstrap-sass playing together
source :rubygems
gem 'shotgun', :group=>:development
gem 'rack-cache'
gem 'sinatra', :require => 'sinatra/base'
gem 'sinatra-support'
gem 'haml'
@leemour
leemour / Rails Generations
Last active December 16, 2015 09:28
Rails generations examples
rails g scaffold Page slug:string title:string parent_id:integer content:text excerpt:string seo_title:string seo_desc:string seo_keys:string
rails g scaffold Product slug:string brand:references name:string type:string price:integer options:text features:text design:text description:text slogan:string
rails g scaffold Brand name:string country:string slogan:string description:text logo:string image:string flag:string
rails g scaffold Category slug:string name:string description:text
Assets precompile:
config.assets.initialize_on_precompile = false #config/application.rb - it works
config.assets.precompile = %w{application.js} #config/application.rb - may work
@leemour
leemour / RSpec default
Created April 18, 2013 19:31
Using RSpec generators by default
rails new myapp -T # excludes Unit Test
# config/application.rb:
config.generators do |g|
g.test_framework :rspec
end
#place this in config/locales/translit.rb
# encoding: utf-8
# I18n transliteration delegates to Russian::Transliteration (we're unable
# to use common I18n transliteration tables with Russian)
#
# Правило транслитерации для I18n использует Russian::Transliteration
# (использовать обычный механизм и таблицу транслитерации I18n с
# русским языком не получится)
@leemour
leemour / Heroku MongoDB
Last active December 16, 2015 11:18
Creating Rails with MongoDB and deploying to Heroku from scratch
rails new app -T --skip-active-record
cd app
# пофиксить sed -i "s/# config.time_zone = 'Central Time (US & Canada)'/config.time_zone = 'Europe/Moscow'/" config/application.rb
sed -i 's/# config.i18n.default_locale = :de/config.i18n.default_locale = :ru/' config/application.rb
echo -e "gem 'mongoid'\n" >> Gemfile
echo -e "group :production do\n gem 'unicorn'\n gem 'newrelic_rpm'\nend\n" >> Gemfile
bundle install
#echo 'web: bundle exec unicorn -p $PORT -E $RACK_ENV' >> Procfile
'web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb' >> Procfile
echo -e 'preload_app true\ntimeout 15' >> config/unicorn.rb
@leemour
leemour / Sed Replace Multiline
Last active December 16, 2015 11:19
Regex to replace end in config files through bash
class Test
def procedure
nil
end
end
I am trying to achieve this:
class Test
def procedure
nil
@leemour
leemour / Layout Haml Bootstrap HTML5 Rails
Last active December 16, 2015 11:29
views/layouts/application.html.haml
!!! 5
%html
%head
%meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}
%title= content_for?(:title) ? yield(:title) : "Rails Test"
%meta{:content => content_for?(:description) ? yield(:description) : "Rails Test", :name => "description"}
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
= yield(:head)