Skip to content

Instantly share code, notes, and snippets.

View joxxoxo's full-sized avatar

Andrei Razhkouski joxxoxo

View GitHub Profile
@joxxoxo
joxxoxo / Procfile
Created October 15, 2012 10:17
Procfile (faye, sunspot, neo4j, resque)
faye: rackup private_pub.ru -s thin -E development
search: bundle exec rake sunspot:solr:run
search_test: bundle exec rake sunspot:solr:run RAILS_ENV=test
neo4j: bundle exec rake neo4j:console
rescue: bundle exec rake resque:work QUEUE='import_queue'
@joxxoxo
joxxoxo / pre-commit
Created October 18, 2012 17:41
git pre commit hook
#!/bin/bash
## START PRECOMMIT HOOK
# git commit .... <-- run with check
# NOCHECK=1 git commit ... <-- run without check
if [ ! "${NOCHECK}" ]; then
files_modified=`git status --porcelain | egrep "^(A |M |R ).*" | awk ' { if ($3 == "->") print $4; else print $2 } '`
for f in $files_modified; do
echo "Checking ${f}..."
if grep --color -n "console.log" $f; then
@joxxoxo
joxxoxo / application.js.erb
Last active December 11, 2015 09:08
Include routes helpers in assets
// <% environment.context_class.instance_eval { include Rails.application.routes.url_helpers } %>
@joxxoxo
joxxoxo / db.rake
Last active December 14, 2015 00:59
Rake > MySQL > backup
namespace :db do
desc 'Create db backup'
task :backup => :environment do
db_config = Rails.configuration.database_configuration[Rails.env]
username = db_config['username']
password = db_config['password']
database = db_config['database']
bak_folder = "#{Dir.home}/backups"
@joxxoxo
joxxoxo / .ackrc
Last active December 14, 2015 08:18
to search through all files and skip not project ones
--type-add=ruby=.haml,.rake, .slim, .feature
--type-add=css=.less,.scss, .sass
--type-add=js=.coffee
--ignore-dir=neo4j
--ignore-dir=tmp
--ignore-dir=coverage
--ignore-dir=log
--ignore-dir=tmp
--ignore-dir=brakeman
--ignore-dir=.idea
@joxxoxo
joxxoxo / scope_operators_initializer.rb
Last active December 14, 2015 08:19
Add 'or' and 'and_not' methods to AR::Relation
module ScopeOperators
def or(other).
left = arel.constraints.reduce(:and)
right = other.arel.constraints.reduce(:and)
scope = merge(other)
left ||= Arel::Nodes::Grouping.new(0) # take none if no conditions
right ||= Arel::Nodes::Grouping.new(0) # take none if no conditions
scope.where_values = [ Arel::Nodes::Grouping.new(left).or(Arel::Nodes::Grouping.new(right)) ]
scope
end
@joxxoxo
joxxoxo / seeds.rb
Created March 22, 2013 15:05
to bypass mass-assignment in seeds
# to bypass mass-assignment
Dir[Rails.root.join('app/models/*')].each {|f| require_dependency f }
ActiveRecord::Base.descendants.each {|m| p m.name; m.attr_accessible(*m.attribute_names)}
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
if defined? SimpleCov
require 'simplecov'
SimpleCov.start 'rails'
end
require 'rails/application'
module Search
class AdvancedProfileSearch < ::Search::Search
attr_reader :search_object, :search_params
def initialize(search_object, search_params)
@search_object, @search_params = search_object, search_params
end
# https://github.com/sunspot/sunspot#readme
class << self
def perform_without_rescue(search_params)
module Search
class Search
class << self
def perform(*args)
results = nil
with_exception_handling { results = perform_without_rescue(*args) }
::Search::SearchResults.new(results)
end
def perform_without_rescue(search_params, *classes)