Skip to content

Instantly share code, notes, and snippets.

View sergii's full-sized avatar

Serhii Ponomarov sergii

View GitHub Profile
@sergii
sergii / digital_ocean_setup.md
Created February 24, 2016 21:30 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

@sergii
sergii / trgm.md
Created June 7, 2016 13:06 — forked from davetoxa/trgm.md

Замечали ли вы, что когда вы набираете что-то в google или yandex с ошибками, вас поправляют?

Возможно вы искали ... ?

Данная концепция называется триграммным поиском, она позволяет искать слова и фразы с опечатками.

Как это работает?

Каждое слово делится на сочетания из 3х букв – триграммы. На примере слова "Россия", будет:

A small clone of Sinatra

For the purpose of learning.

Run the example app

@sergii
sergii / template.rb
Created June 7, 2016 13:07 — forked from route/template.rb
AR template
class Example < ActiveRecord::Base
## included modules & attr_*
## associations
## plugins
## named_scopes
## validations
## callbacks
## class methods
## public methods
## protected methods
module CheckedAttributes
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def attr_checked(attribute, &validation)
define_method "#{attribute}=" do |value|
raise 'Invalid attribute' unless validation.call(value)
instance_variable_set("@#{attribute}" , value)
end
@sergii
sergii / capybara_webkit_screenshot_env.rb
Created June 22, 2016 09:23 — forked from mattheworiordan/capybara_webkit_screenshot_env.rb
Cucumber and Capybara-Webkit automatic screenshots on failure
def screen_shot_and_save_page
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
Capybara.save_page body, "#{path}.html"
page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
end
begin
After do |scenario|
screen_shot_and_save_page if scenario.failed?
@sergii
sergii / price.md
Created December 1, 2016 09:53 — forked from justjanne/Price Breakdown.md
AWS Lightsail vs DigitalOcean, VULTR and Linode

Price breakdown vs DigitalOcean, Vultr, Linode, OVH, and Online.net / Scaleway:

$5/mo

Provider RAM Cores Storage Transfer
LightSail 512MB 1 20GB SSD 1TB
DO 512MB 1 20GB SSD 1TB
@sergii
sergii / feature_test.md
Created December 6, 2016 10:45 — forked from chaomao/feature_test.md
list everything about feature test

Automation Test

  • End to End Test
  • Integration Test
  • Unit Test

In my mind, smoking test is end to end test, feature test is integration test. We want to enable everybody writing automation test.

End To End Test

@sergii
sergii / custom_logger.rb
Created February 16, 2017 11:26 — forked from kinopyo/custom_logger.rb
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere