Skip to content

Instantly share code, notes, and snippets.

View osulyanov's full-sized avatar
🎯
Focusing

Oleg osulyanov

🎯
Focusing
  • Passion.io
View GitHub Profile
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
mkdir ~/bin
export PATH=~/bin:$PATH
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
export EDITOR='subl -w'
git config --global core.editor "subl -n -w"
@osulyanov
osulyanov / copy_paperclip_data.rb
Created January 28, 2013 06:45
Move existing Paperclip attachments to a new path Case in: lib/tasks/copy_paperclip_data.rb And run: rake copy_paperclip_data
desc "Copy paperclip data"
task :copy_paperclip_data => :environment do
@users = User.find :all
@users.each do |user|
unless user.image_file_name.blank?
filename = Rails.root.join('public', 'system', 'images', user.id.to_s, 'original', user.image_file_name)
if File.exists? filename
image = File.new filename
user.image = image
@osulyanov
osulyanov / application.css
Created February 7, 2013 10:41
Custom file input
.file_upload {
position: relative;
overflow: hidden;
float: left;
margin-right: 4px;
}
.file_upload input {
position: absolute;
top: 0;
right: 0;
@osulyanov
osulyanov / gist:4761923
Created February 12, 2013 12:12 — forked from moiristo/gist:1245170
Rails3 way to redirect non-www domain to www domain
# Rails3 way to redirect non-www domain to www domain
# Single domain redirect
'example.com'.tap do |host|
constraints(:host => host) do
match '/(*path)', :to => redirect { |params, request| Addressable::URI.escape request.url.sub(host, "www.#{host}") }
end
end
@osulyanov
osulyanov / Gemfile
Last active December 12, 2015 10:49
Redirect to www version and remove trailing slash
gem 'rack-rewrite'
@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 / 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 / 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 / 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