Skip to content

Instantly share code, notes, and snippets.

if (typeof jQuery === 'function') {
var oQuery = jQuery.noConflict(true);
}
/*!
* jQuery JavaScript Library v1.7.2
* http://jquery.com/
*
* Copyright 2011, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
if (typeof jQuery === 'function') {
var oQuery = jQuery.noConflict(true);
}
/*!
* jQuery JavaScript Library v1.7.2
* http://jquery.com/
*
* Copyright 2011, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
if (typeof jQuery === 'function') {
var oQuery = jQuery.noConflict(true);
}
/*!
* jQuery JavaScript Library v1.7.2
* http://jquery.com/
*
* Copyright 2011, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
@rafael
rafael / install-script
Created June 20, 2013 21:01
Install script for skyscrpr
<script id="skyscrpr-config-script">
var skyscrprSettings={site_id:'17d45be8-e962-11e1-99e6-1231380fc676',};
</script>
<script>
(function(){
function async_load(){
var scr=document.createElement('script');
scr.type='text/javascript';
scr.async=true;
@rafael
rafael / publish_action.rb
Created October 28, 2013 16:29
publish static page.
def publish
html = render_to_string(template: "media_kits/preview",
layout: 'application' )
cache_page(html, "media_kits/#{@media_kit.publisher_profile.fqdn}")
redirect_to media_kit_path(@media_kit), notice: 'Media Kit Published'
end
@rafael
rafael / cache_page.rb
Created October 28, 2013 16:35
Cache page based on actionpack_page_caching
require 'fileutils'
module Openair
module CachePage
# This methods come from action_pack/cache_page'
# https://github.com/rails/actionpack-page_caching
# We didn't need the whole gem. So I decided to get
# just what we need :)
def cache_page(content, path, extension = '.html', gzip = Zlib::BEST_COMPRESSION)
path = page_cache_path(path, extension)
FileUtils.makedirs(File.dirname(path))
@rafael
rafael / static_rack.rb
Last active December 26, 2015 19:19
statics file server rack.
require 'rack/utils'
class StaticRack
def call(env)
path = env["SERVER_NAME"]
file, headers = pick_file_and_headers_for_path(path, env)
file_server = ::Rack::File.new(file, headers)
file_server.call(env)
end
private
@rafael
rafael / static_file_server_rack.rb
Last active December 26, 2015 19:19
Rack to serve statics files with a middleware
require 'rack/utils'
module Openair
class MediaKitStaticRack
def initialize
@middlewares = [:bugsnag]
@middlewares << :errors unless Rails.env.development?
end
def call(env)
@app = load_app
require 'rack/utils'
class StaticFileServer
def initialize
@middleware_stack = ActionDispatch::MiddlewareStack.new
@middleware_stack.use ActionDispatch::ShowExceptions, show_exception_app unless Rails.env.development?
@middleware_stack.use Bugsnag::Rack
end
def call(env)
@rafael
rafael / rails.rb
Created November 5, 2013 18:30
Include a module into action controller when loading a gem.
class Engine < Rails::Engine
initializer 'imprenta.controller_methods' do |app|
ActionController::Base.send :include, Imprenta::CachePage
end
end