Skip to content

Instantly share code, notes, and snippets.

View firedev's full-sized avatar
👁️
👁

Nick Ostrovsky firedev

👁️
👁
View GitHub Profile
@firedev
firedev / Railscasts.tmTheme
Created June 18, 2012 11:56
Improved Railscasts Theme for Sublime Text 2 – Makes sure you have a differently colored text selection instead of black on black
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0.sublime">
<dict>
<key>name</key>
<string>Railscasts</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@firedev
firedev / localized.rb
Last active March 27, 2020 04:53
Easy localization for Rails model attributes. Models should have attributes ending with `_<locale>`, i.e. `title_en`, `title_ru`. `attr_translated :title` will add a `.title` method. If `.title_<current_locale>` is empty, `.title_en` will be returned.
# localized.rb
#
# Usage:
#
# include Localized
# attr_translated :title
#
# Model.title now returns title_<locale> or falls back to title_en
#
@firedev
firedev / autoslug.rb
Last active December 13, 2015 16:48
Creates :slug from given :title when creating models if no :slug given
# autoslug.rb
#
# Usage:
#
# include Autoslug
# attr_slug :title [, :slug] [, &block]
#
# Creates :slug from given :title when creating models if no :slug given
# Uses parameterize by default or can run :title through a &block:
#
@firedev
firedev / nav_link_to_helper.rb
Last active December 15, 2015 19:09
Provides a `nav_link_to` view helper method that mimics `link_to` but adds a `selected` class if the link equals current page. Put into `intializers`.
@firedev
firedev / kaminari.rb
Created May 23, 2013 05:53
Fix for Kaminari strange window implementation. Works with Kaminari 0.13
# Fixes https://github.com/amatsuda/kaminari/issues/133
# put into /initializers/kaminari.rb
module Kaminari
module Helpers
class Paginator < Tag
class PageProxy
def inside_window?
if @options[:current_page] <= @options[:window]
@page <= (@options[:window] * 2) + 1
@firedev
firedev / application_controller.rb
Last active January 1, 2016 07:09
Make Action Mailer use request host and protocol for images and links in emails.
# application_controller.rb
class ApplicationController < ActionController::Base
before_action :make_action_mailer_use_request_host_and_protocol
def make_action_mailer_use_request_host_and_protocol
ActionMailer::Base.default_url_options[:protocol] = request.protocol
ActionMailer::Base.default_url_options[:host] = request.host_with_port
ActionMailer::Base.asset_host = "#{request.protocol}#{request.host_with_port}"
end
@firedev
firedev / Solarized (Firedev).tmTheme
Created January 9, 2014 09:53
Put this in `~/Library/Application Support/Sublime Text 3/Packages` and add the following line in config: ``` "color_scheme": "Packages/Solarized (Firedev).tmTheme", ```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Solarized (Firedev)</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@firedev
firedev / routing_helper.rb
Created January 21, 2014 14:41
Fix for Rails locales when testing with Rspec, Capybara etc...
# spec/support/routing_helper.rb
class ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
def call(t, args)
t.url_for(handle_positional_args(t, args, { locale: nil }.merge( @options ), @segment_keys))
end
end
@firedev
firedev / nav_link_to_controller_helper.rb
Last active August 29, 2015 13:56
Provides a `nav_link_to_controller` view helper method that works like `nav_link_to` https://gist.github.com/firedev/5308768 but also adds `selected` CSS class if the link equals current page or handled by the same controller.
@firedev
firedev / kaminari.rb
Created February 7, 2014 11:14
Kaminari pager fix – keeps consistent number of pages on the screen
# config/initializers/kaminari.rb
module Kaminari
module Helpers
class Paginator < Tag
def relevant_pages(options)
1..options[:total_pages]
end
class PageProxy