Skip to content

Instantly share code, notes, and snippets.

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
# rvm_lib_path = File.join(rvm_path, 'lib')
# $LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
raise "RVM ruby lib is currently unavailable."
end
module ActiveSupport
module PagedScope
def self.extended(base)
base.scope :paginated, lambda { |page,per_page|
page ||= 0
per_page ||= 25
base.limit( per_page.to_i ).offset( per_page.to_i * page.to_i )
}
end
# Used to parse ActionScript style annotations
# [Annotation(key="value",foo="bar")]
# Where Annotation is the name and key and foo are attribute names.
# Quick string matching, does not create an "Annotation Object"
# for now, though that would be an improvement.
class AS3AnnotationParser
#Does the given annotation exist in the provided string?
def self.has_annotation (contents, name)
contents.match(/\[#{name}[^\]]?+\]/) != nil
end
@bogdanRada
bogdanRada / rails_routes_multiple_files.rb
Last active January 3, 2016 20:39 — forked from dhh/gist:2492118
rails_routes_multiple_files.rb
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
# Render Partials in ECO-Templates like in Rails-ERB
#
# usefull to clean up structure in spine.js and other js-mvc´s like backbone
#
# usage:
# <%- render_partial 'path/to/partial' %> .. will render ../spine-app/views/path/to/_partial.jst.eco
# <%- render_partial 'path/to/partial', foo: 'bar' %> .. will render ../spine-app/views/path/to/_partial.jst.eco .. locals = @foo
#
window.render_partial = ( path, options = {} ) ->
# add the leading underscore (like rails-partials)
@bogdanRada
bogdanRada / check_assets_valid_encoding.rake
Last active August 31, 2015 10:35 — forked from shedd/assets.rake
check assets have valid encoding
namespace :assets do
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")

Create an .htaccess file in the webroot:

AuthUserFile /app/www/.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user

Create a .htpasswd file:

htpasswd -c /app/www/.htpasswd [username]

require 'nokogiri'
module ActionView
module TemplateHandlers
class Nokogiri < TemplateHandler
include Compilable
def compile template
<<-eotemplate
_set_controller_content_type(Mime::XML)
@bogdanRada
bogdanRada / rake_heroku_deployer.rb
Last active August 31, 2015 10:29 — forked from jfeaver/deploy.rake
rake_heroku_deployer.rb
#Deploy and rollback on Heroku in staging and production
class RakeHerokuDeployer
def initialize app_env
@app = ENV["#{app_env.to_s.upcase}_APP"]
end
def run_migrations
push; turn_app_off; migrate; restart; turn_app_on; tag;
end
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end