Skip to content

Instantly share code, notes, and snippets.

@simonmcmanus
simonmcmanus / frax.js
Last active December 15, 2015 10:29
PJAX as Page.js middleware.
var frax = function(context, next) {
if(!context.init) {
$.get(context.canonicalPath+'?_pjax=true', function(markup) {
if(context.delay) {
context.pending = markup;
}else {
context.container.html(markup); // cached $('#container')
}
next();
});
@sj26
sj26 / journey_coffee_generator.rb
Created April 10, 2013 03:53
Generate rails-like route helpers for use in javascript land
class JourneyCoffeeGenerator < Journey::Visitors::Visitor
def accept node
@requirements = [[]]
super.gsub('" + "', '')
end
private
def visit_GROUP node
@requirements << []
@javan
javan / application_controller.rb
Created November 30, 2013 22:06
Prevent cross-origin js requests
class ApplicationController < ActionController::Base
before_filter :ensure_xhr
private
def ensure_xhr
if request.get? && request.format && (request.format.js? || request.format.json?)
head :forbidden unless request.xhr?
end
end
end
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@domgetter
domgetter / havewant.rb
Last active August 3, 2016 20:19
Will tell you what Ruby method(s) you want given the input and output Now works with arguments!
class HaveWant
attr_reader :answers
def initialize(*have, want)
@have = have[0]
@args = have[1..-1]
@want = want
find_matches