Skip to content

Instantly share code, notes, and snippets.

View firedev's full-sized avatar
👁️
👁

Nick Ostrovsky firedev

👁️
👁
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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:
#