Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
bogdanRada / mountable engine Rspec controller test.rb
Created January 20, 2014 11:06
mountable engine Rspec controller test
module ControllerHacks
def get(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "GET")
end
# Executes a request simulating POST HTTP method and set/volley the response
def post(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "POST")
end
@bogdanRada
bogdanRada / Set session for integration tests Rails.rb
Last active March 31, 2020 06:15
Set session for integration tests Rails
class RackSessionTestMiddleware
class << self
def session_data
@@session_data||={}
end
def session_data=(value)
@bogdanRada
bogdanRada / Here is a fast and easy way of parsing query strings in JavaScript:.js
Created February 6, 2014 09:33
Here is a fast and easy way of parsing query strings in JavaScript:
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
console.log('Query variable %s not found', variable);
# 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
# This module allows you to prepend a version prefix to your Sinatra URLs
# Example:
#
# require 'rubygems'
# require 'sinatra/base'
#
# class App < Sinatra::Base
# register Versioned
#
# set :version, 'v1'