Skip to content

Instantly share code, notes, and snippets.

@rocLv
rocLv / postgresql_configuration_on_ubuntu_for_rails.md
Created December 4, 2016 14:27 — forked from p1nox/postgresql_configuration_on_ubuntu_for_rails.md
PostgreSQL configuration without password on Ubuntu for Rails

Abstract

You could have postgre installed on localhost with password (or without user or password seted after instalation) but if we are developing we really don't need password, so configuring postgre server without password for all your rails project is usefull.

Install Postgre packages

  • postgresql
  • postgresql-client
  • libpq-dev
@rocLv
rocLv / Rails Controller.md
Created February 22, 2017 10:27 — forked from stevenyap/Rails Controller.md
Rails controller cheatsheet

Flash

# supports only notice and alert by default
# the rest has to go into flash hash
redirect_to :index, notice: "success"
redirect_to :new, notice: "errors"
redirect_to :new, flash: { success: "yeah" }
flash[:info] = "updated"
@rocLv
rocLv / imagemagick-install-steps
Last active March 1, 2017 04:07 — forked from rodleviton/imagemagick-install-steps
Installing Image Magick on Ubuntu 14.04
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xzvf ImageMagick-6.8.9-1.tar.gz
cd ImageMagick-6.8.9-1/
./configure --prefix=/opt/imagemagick-6.8 && make
checkinstall
if &compatible
set nocompatible
end
filetype off
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
" Let Vundle manage Vundle
Plugin 'gmarik/Vundle.vim'
@rocLv
rocLv / model.rb
Last active March 14, 2017 08:58
# lib/templates/active_record/model/model.rb
<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
# keep the default scope first (if any)
# constants come up next
# afterwards we put attr related macros
# followed by association macros
You can specify an explicit logger in your config;
my_logger = ActiveSupport::BufferedLogger.new(path)
config.logger = my_logger
This will replace Rails.logger
@rocLv
rocLv / upgrade_pg.sh
Last active December 12, 2018 02:44 — forked from edib/upgrade_pg.sh
Upgrade PostgreSQL 9.3 to 9.6 on Ubuntu 16.04
Create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6 postgresql-server-dev-9.6 postgresql-contrib-9.6 -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
require_relative 'boot'
require 'csv'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Giant
class Application < Rails::Application
Rails 4 - Respond only to JSON and not HTML
I believe there are 2 parts here:
1) json only requests in rails
2) json only responses in rails
1) Configure your application controller to ensure json requests only
# app/controller/application_controller.rb
before_action :ensure_json_request
@rocLv
rocLv / 0_reuse_code.js
Created March 31, 2017 08:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console