Skip to content

Instantly share code, notes, and snippets.

View osulyanov's full-sized avatar
🎯
Focusing

Oleg osulyanov

🎯
Focusing
  • Passion.io
View GitHub Profile
@osulyanov
osulyanov / functions.js
Created November 11, 2013 03:31
Scroll AJAX page load
// Подгрузка страниц при скроллинге
var thisWork = 1;
function getNextP() {
if( !$('div').is('#products') )
return false;
if(thisWork == 1) {
nextPageNum = $("#products").data('page') + 1;
if(nextPageNum>$("#products").data('pages'))
@osulyanov
osulyanov / .powrc
Created July 25, 2013 03:58
Using Pow with RVM
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ]; then
source "$rvm_path/scripts/rvm"
rvm use `cat .ruby-version`
fi
@osulyanov
osulyanov / controller.rb
Created July 24, 2013 03:55
If-Modified-Since header check
def show
@show = Show.find(params[:id])
if stale?(:etag => @show, :last_modified => @show.updated_at.utc)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @show }
end
end
end
@osulyanov
osulyanov / config_application.rb
Last active December 14, 2015 18:58
Page not found exception handling
config.exceptions_app = self.routes
@osulyanov
osulyanov / application_controller.rb
Created February 21, 2013 02:43
Separate layouts for other requests
layout proc {|controller| controller.request.xhr? ? "ajax": "application" }
@osulyanov
osulyanov / category_constraint.rb
Created February 18, 2013 05:05
Dynamic routing
class CategoryConstraint
def self.matches?(request)
Category.where(alias: request.path_parameters[:categoryalias]).first
end
end
@osulyanov
osulyanov / config_initializers_pluralization.rb
Last active December 13, 2015 21:08
Rails start russian locales set
require "i18n/backend/pluralization"
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
@osulyanov
osulyanov / plurals.rb
Last active December 13, 2015 21:08
Plurals localize
# -*- encoding: utf-8 -*-
# Правило плюрализации для русского языка, взято из CLDR, http://unicode.org/cldr/
#
# Russian language pluralization rules, taken from CLDR project, http://unicode.org/cldr/
#
# one -> n mod 10 is 1 and n mod 100 is not 11;
# few -> n mod 10 in 2..4 and n mod 100 not in 12..14;
# many -> n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14;
# other -> everything else
@osulyanov
osulyanov / en.yml
Last active December 13, 2015 16:49 — forked from nbibler/en.yml
Custom model field validation
en:
errors:
models:
model_name:
attributes:
field_name:
reserved: Такое имя пользователя зарезервированно
@osulyanov
osulyanov / Gemfile
Last active December 12, 2015 10:49
Redirect to www version and remove trailing slash
gem 'rack-rewrite'