Skip to content

Instantly share code, notes, and snippets.

View rossmari's full-sized avatar
🏠
Working from home

Roman Buzhenko rossmari

🏠
Working from home
  • Russian Federation, Krasnoyarsk
View GitHub Profile
@rossmari
rossmari / spec_helper.rb
Created July 4, 2014 01:57
valid spec_helper for rspec3
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
@rossmari
rossmari / staging.rb
Created July 4, 2014 08:08
task to start rspec before deploy
desc 'Start rspec before deploy'
task :rspec, :roles => :app do
puts 'Starting rspec examples ... prepare to be punished!'
output = %x[bundle exec rspec]
respond = output.split(/\n/)
if respond.any? { |e| e.match(/Failures:/)}
set(:confirmed) do
puts "\n\t#{'='*75}\n\n\tThere are errors:\n\n\t>>> #{respond.detect { |e| e.match(/.*failure.*/) }.upcase}\n\n\t#{'='*75}\n"
Capistrano::CLI.ui.ask("\n\tAre you sure you want to continue? (Y) ") == 'Y' ? true : false
end
@rossmari
rossmari / tips.md
Last active August 29, 2015 14:04
Device mountable, using devise in engine (isolated and non-isolated)
@rossmari
rossmari / visit_events.js
Last active August 29, 2015 14:05
crazy way to inspect page visits count and site visits count
$(function()
{
//============ Subscribe on events example ==
// $(document).on('pvc_changed', function(event, pvc_count){
// alert(pvc_count);
// });
//
// $(document).on('svc_changed', function(event, svc_count){
// alert(svc_count);
// });
//before code to detect browser and change some link
var user_agent = navigator.userAgent;
function userAgentCheck(r) {
return r.test(user_agent);
}
function changeBrowserExtensionLink() {
if (userAgentCheck(/OPR/)) {
@rossmari
rossmari / shitcode_1.erb
Last active August 29, 2015 14:05
epic_piece_of_shit.rb
<% #Founded in old legacy project - epic crazy piece of BAD code %>
<div id="second_body">
<% #TODO Переделать нижележащий кусок кода нахрен: %>
<%- content = capture do -%>
<%- if article.article_type != Article::ANNOUNCEMENT -%>
<%- right_articles = article.right_articles.actual.all(:conditions => "type != 'ArtDossier'") -%>
<% #NOTE Вот согласно этому куску - правые - на которых мы ссылаемся, а левые - которые на нас ссылаются. %>
<%- incut_size = article.incuts.size + (article.poll ? 1 : 0) + (right_articles.any? ? 1 : 0) -%>
<%- doc = Hpricot(formating_text(article.content)) -%>
<%- p_tags_raw = doc.search("/") -%>
@rossmari
rossmari / dossiers_dialogs_dossiers.js
Last active August 29, 2015 14:06
ckeditor plugin with crazy semaphore
CKEDITOR.dialog.add( 'dossiersDialog', function ( editor ) {
var selectedPersonId = null;
var semaphoreActive = false;
var start_inputs_value = 1;
var inputs_count = 1;
var searchValue = '';
var person_select = null;
@rossmari
rossmari / villages_slider_filter.rb
Last active August 29, 2015 14:06
search params processor for sliders
class VillagesSliderFilter
VILLAGE_SORT_PARAMS = { price: { range: true },
distance: { range: false },
area_price: { range: false },
land_price: { range: true } }
VILLAGE_JOINS = [:builders, :village_odds, :building_types, :directions]
def initialize(params)
@rossmari
rossmari / event_logger.rb
Last active August 29, 2015 14:07
Store changes for any model
class Magazine::EventLogger
attr_reader :history
FIELD_EXCEPTIONS = [:updated_at]
@namespace = 'Magazine::'
@suffix = 'Event'
def initialize(object)
@rossmari
rossmari / publication_form_presenter.rb
Created October 9, 2014 07:11
50% of multi class form presenter - #useless
class Magazine::FormPresenter < ActiveRecord::Base
# === CONSTANTS
CONSTANT_EXCEPT = [:id, :created_at, :updated_at, :type]
# === COLUMN METHODS
class << self
def columns
@columns ||= [];
end