Skip to content

Instantly share code, notes, and snippets.

View costa's full-sized avatar

Costa Shapiro costa

View GitHub Profile
@costa
costa / i18n_test.rb
Created January 16, 2014 12:45
a proper config/initializer to catch all the i18n errors (hopefully) within rails 3.2 test environment
if Rails.env.test?
module I18n
def self.just_raise_that_exception(*args)
raise args.first
end
end
I18n.exception_handler = :just_raise_that_exception
module ActionView::Helpers::TranslationHelper
def translate_with_raise(key, options = {})
@costa
costa / less_stupid_translation_helper.rb
Created January 23, 2014 14:12
Less stupid translation helper (with blocks for interpolation) until https://github.com/rails/rails/pull/13808 makes it into a version (and if at all)
module LessStupidTranslationHelper
include ActionView::Helpers::TranslationHelper
class Interpolator
attr_reader :variables
def initialize(context)
@variables = HashWithIndifferentAccess.new
@context = context
@costa
costa / mail_spec.rb
Created March 30, 2014 12:04
Re-using mail_view's "actions" for basic Rails view specs. -> ./specs/views/
describe MailPreview do
MailPreview.new.public_methods(false).each do |e|
example "##{e}" do
subject.send(e).should_not be_blank
end
end
end
@costa
costa / _development_.rb
Last active August 29, 2015 14:02
put this in your rails project's config/environments/development.rb (or your platform's equivalent); see http://mines.mouldwarp.com/2014/06/pow-and-byebug-staying-in-web-app-dev.html
if ENV['RUBY_DEBUG_PORT'] # NOTE no RUBY_DEBUG_PORT in the environment means no remote debugging, okay?
Byebug.start_server 'localhost', ENV['RUBY_DEBUG_PORT'].to_i
end
#!/usr/bin/env ruby
# NOTE current directory is assumed
# NOTE run with 'rm {}' to remove duplicate copies (while taking necessary caution)
exec_command = ARGV[0] || 'echo {}'
require 'digest/md5'
require 'shellwords'
filenames_by_md5 = {}
require 'digest/md5'
hash = {}
Dir.glob("**/*", File::FNM_DOTMATCH).each do |filename|
next if File.directory?(filename)
# puts 'Checking ' + filename
key = Digest::MD5.hexdigest(IO.read(filename)).to_sym
if hash.has_key? key
[ -r $HOME/.bashrc ] && . $HOME/.bashrc
@costa
costa / i18n-ext.js.coffee
Last active August 29, 2015 14:08
An experimental extension for https://github.com/fnando/i18n-js
#= require i18n
# XXX experiment
I18n._boring_translate = I18n.translate
I18n.t = I18n.translate = (scope, options)->
if typeof scope == 'string' && scope[0] == '.'
scope = scope.slice 1
options ||= {}
options.scope ||= I18n._local_scope
@costa
costa / pusher.rb
Last active August 29, 2015 14:10
Rails-Pusher integration: config/initializers
if defined? PusherFake
PusherFake.configure do |config|
config.logger = Rails.logger
config.verbose = true
# NOTE won't work with DJ pushing OR with a pre-defined port
config.socket_options = {host: ENV['DOMAIN_NAME'], port: config.send(:available_port)}
end
require 'pusher-fake/support/base' if ENV['FAKE_PUSHER'] # NOTE should be set for a single process only
@costa
costa / pusher_context.rb
Last active August 29, 2015 14:10
Rails/Rspec context for stubbing Pusher in tests: spec/support
shared_context "pusher server client" do
before do
@_pusher_stub = stub_pusher if do_stub_pusher && !@_pusher_stub
end
after do
remove_request_stub @_pusher_stub if @_pusher_stub
@_pusher_stub = nil
end