Skip to content

Instantly share code, notes, and snippets.

View st8998's full-sized avatar

Ivan Efremov st8998

View GitHub Profile
@st8998
st8998 / js_named_routes.rb
Created June 30, 2011 13:58
Rails routs in JS
def include_js_routes
script = "<script>window.Routes = {};"
Rails.application.routes.routes.each do |route|
script += "Routes.#{route.name}_path = function(params) {return $.buildPath('#{route.path}', params);};"
end
script += "</script>"
script.html_safe
end
@st8998
st8998 / blank_safe_helper.rb
Created July 1, 2011 08:37
Blank Safe Helper
def blank_safe value, guard = '<span class="NA">n/a</span>'.html_safe
value.presence || guard
end
alias bs blank_safe
$.buildPath = (path, params...) ->
extraParams = {}
paramsHash = {}
if $.isPlainObject(lastParam = params.pop()) then paramsHash = lastParam
else params.push(lastParam)
$.each params, (_, value) ->
replacement = "/#{value}"
path = path.replace /\/:[\w_]+/, replacement
@st8998
st8998 / assets_management.gemspec
Created October 13, 2011 11:46
DB assets managment
Gem::Specification.new do |s|
s.name = 'assets_management'
s.version = '1.0.3'
s.platform = Gem::Platform::RUBY
s.author = 'Ivan Efremov'
s.email = 'st8998@hotmail.com'
s.summary = 'DB assets management utility'
s.description = 'DB assets management utility'
s.files = ['db_assets.rake', 'assets_management.rb', 'mp_postgresql_adapter.rb']
@st8998
st8998 / resque_helper.rb
Created October 21, 2011 19:15
Resque model helper
module ResqueHelper
extend ActiveSupport::Concern
module InstanceMethods
def async(method, *args)
if Settings.async_processing
Resque.enqueue(self.class, id, method, *args)
else
self.reload.send method, *args
@st8998
st8998 / Gemfile
Created February 25, 2012 09:36
Snippet Service
source :rubygems
gem 'thin', :platform => :ruby
gem 'rack-uploads'
@st8998
st8998 / gist:4152813
Created November 27, 2012 06:53
Symbol Query Extensions
class Symbol
delegate :gt, :desc, :asc, to: :attr
def attr
attr = Arel::Attributes::Attribute.new
attr.name = self
attr
end
@st8998
st8998 / gist:4219086
Created December 5, 2012 20:13
Experiment
where_scope, order_scope = Arel::Builder.build do
tsvector = n(TsVector, language, n(ConcatWs, ' ', *columns))
tsquery = n(Tsquery, language, n(ConcatWs, operator, *terms))
rank_tsvector = tsvector
if options[:rank_columns].present?
rank_columns = options[:rank_columns].map {|n| t[n] }
rank_tsvector = n(TsVector, language, n(ConcatWs, ' ', *rank_columns))
end
def try_to_pick_combination
zip_to_lookup = prepare_zip_to_decode
default_data = {
:country => country,
:state => state,
:raw_line_1 => raw_line_1,
:raw_line_2 => raw_line_2,
:raw_line_3 => raw_line_3,
:raw_zip => raw_zip,
:city => city
module ApplicationHelper
def define_helper name, force = false, &block
if !respond_to?(name) || force
self.class.send(:define_method, name) do |*args|
capture(*args, &block)
end
else
raise 'Your inline helper conflicts with already defined helper'
end