Skip to content

Instantly share code, notes, and snippets.

@romansklenar
romansklenar / devise_mailer.rb
Last active December 11, 2015 23:38
custom Devise mailer
class DeviseMailer < ApplicationMailer
include Devise::Mailers::Helpers
def confirmation_instructions(record)
devise_mail(record, :confirmation_instructions)
end
def reset_password_instructions(record)
devise_mail(record, :reset_password_instructions)
end
@romansklenar
romansklenar / devise_resolver.rb
Created January 30, 2013 23:50
Devise template inheritance resolver
# Use only in devise overriden controllers to ensure template inheritance.
# Appending resolver will try to find template in app/views/users/passwords/new
# and it doesn't then it will fallback to app/views/devise/passwords/new
#
# ==== Usage
#
# class Users::PasswordsController < ::Devise::PasswordsController
# append_view_path DeviseResolver.new
# end
#
@romansklenar
romansklenar / README.md
Last active July 11, 2023 23:12
Rails concerns

What is it?

Collection of concerns for your Rails application

Installation

Copy to your app/models/concerns directory

@romansklenar
romansklenar / REAME.md
Last active June 9, 2025 07:28
How to set up your VPS with Chef Solo

How to set up your VPS with Chef Solo

1. What is it?

There are many different provisioning tools out there, the most popular of which are Chef and Puppet. Chef uses Ruby, Puppet uses a DSL (Domain Specific Language), there are others that use simple bash too, but today we're going to focus on Chef Solo.

2. Dependencies

To get Chef working properly on your local machine you need a few things.

Make sure you use Ruby 1.9.x and not Ruby 2.x as you will get errors with the json 1.6.1 gem on 2.x. Use rbenv or RVM to manage several different Rubies on the one machine.

@romansklenar
romansklenar / rails_proficiency.txt
Created December 4, 2013 20:11
Proficiency requirements for Rails developer
Senior (enterprise)
Analyse and profile an application for performance and memory issues
Analyses and profile an application for security issues
Understand database modeling and query analysis
Tune a production deployment (Passenger, Thin, Apache etc)
Understand and use Ruby metaprogramming
Mentoring skills
Communication skills
Planning and Estimation
@romansklenar
romansklenar / 20131118172653_create_transactional_items_view.rb
Last active July 3, 2017 09:15
Using PostgreSQL's materialized views as background for ActiveRecord models for flexible statistics
# db/migrate/20131118172653_create_transactional_items_view.rb
class CreateTransactionalItemsView < ActiveRecord::Migration
def up
select_sql = File.open("#{Rails.root}/db/migrate/20131118172653_create_transactional_items_view.sql", 'r') { |f| f.read }
# for materialized view:
view_sql = "CREATE MATERIALIZED VIEW transactional_items AS (#{select_sql})"
# for normal view:
view_sql = "CREATE VIEW transactional_items AS (#{select_sql})"
@romansklenar
romansklenar / crosstab.sql
Last active February 1, 2023 18:46
PostgreSQL "pivot table" example using tablefunc extension
CREATE EXTENSION tablefunc;
CREATE TABLE sales(year int, month int, qty int);
INSERT INTO sales VALUES(2007, 1, 1000);
INSERT INTO sales VALUES(2007, 2, 1500);
INSERT INTO sales VALUES(2007, 7, 500);
INSERT INTO sales VALUES(2007, 11, 1500);
INSERT INTO sales VALUES(2007, 12, 2000);
INSERT INTO sales VALUES(2008, 1, 1000);
INSERT INTO sales VALUES(2009, 5, 2500);
class Player
def play_turn(warrior)
warrior.walk!
end
end
@romansklenar
romansklenar / commands.sh
Created April 26, 2014 17:28
Rails 4.1 application update diff
rails _3.2.15_ new rails_update --database=postgresql --skip-bundle
rails _4.1.0_ new rails_update --database=postgresql --skip-bundle