Skip to content

Instantly share code, notes, and snippets.

View firedev's full-sized avatar
👁️
👁

Nick Ostrovsky firedev

👁️
👁
View GitHub Profile
@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
@firedev
firedev / sluggable_model.rb
Last active August 29, 2015 13:57
Creates :slug from given :title if no :slug given
# app/models/concerns/sluggable_model.rb
#
# https://gist.github.com/firedev/9701874
#
# Usage:
#
# rails g migration addSlugToModel slug:string:uniq
#
# include SluggableModel
# attr_slug :title [, :slug] [, &block]
@firedev
firedev / development.rb
Last active August 29, 2015 13:58
MockSMTP/MailCatcher sniffer for your development.rb
# config/environments/development.rb
require "net/smtp" # don't forget to add this first
# Try to sniff out if MockSMTP or MailCatcher is running
begin
smtp = Net::SMTP.start "localhost", 1025
if smtp.started?
smtp.quit
puts ">> Emails WILL be sent to the SMTP server on port 1025"
@firedev
firedev / readmarkable.rb
Created June 7, 2014 05:04
ReadMarkable
module ReadMarkable
extend ActiveSupport::Concern
included do
has_many :read_marks
def touch_read_at
update_column(:read_at, Time.now)
end
@firedev
firedev / metable_model.rb
Last active August 29, 2015 14:02
Creates :meta from given :body when saving models
# app/models/concerns/metable_model.rb
#
# https://gist.github.com/firedev/644b41967cf6c1c9d035
#
# Usage:
#
# rails g migration addMetaToModel meta:string
#
# include MetableModel
# metable [:meta] [, :body] [, &block]
@firedev
firedev / translit.rb
Last active August 29, 2015 14:03
Converts russian strings to english translit
# translit.rb
#
# https://gist.github.com/firedev/128521f9cc8d63eaff77
#
# Converts russian strings to english translit
#
# Usage:
#
# Translit.(string)
@firedev
firedev / decorated.rb
Last active August 29, 2015 14:04
Hides Draper decorator inside the model and lazily decorates resources
# Hides Draper decorator inside the model and lazily decorates resources
#
# https://gist.github.com/firedev/7a82059b30a2157d4c56
#
# model.rb:
# include Decorated
#
# Just make sure there are no overlapping method names in ModelDecorator
module Decorated
@firedev
firedev / seed.rb
Last active August 29, 2015 14:04
Seed.rb - imports records from .yml files
# db/seeds.rb
#
# https://gist.github.com/firedev/5d9cd290da97d3c131e3
#
# Imports records from .yml files in db/seed/model.yml
def put_cycle
@r ||= %w(- \\ | /)
print((@r << @r.shift)[0])
print "\b"
@firedev
firedev / record_not_found.rb
Created August 8, 2014 11:04
Redirects visitor up the restful route if record not found
# controllers/concerns/record_not_found.rb
#
# Redirects visitor up the restful route if record not found
#
# /articles/404 -> /articles/ -> /
module RecordNotFound
extend ActiveSupport::Concern
included do