Skip to content

Instantly share code, notes, and snippets.

View dylanz's full-sized avatar
🐝

Dylan Stamat dylanz

🐝
View GitHub Profile
w00t !
## awesomeness
[:get, :post, :put, :delete, :render, :request].each do |action|
eval %Q{
def before_#{action}
yield
require 'resolv'
require 'memcached'
module Rack
module JSONP
>> @something.to_json
=> {"foo": "bar"}
>> params[:callback]
=> "aoeu"
>> render :json => @something.to_json, :callback => params[:callback]
=> aoeu({"foo": "bar"})
location ~* \.(json)$ {
set memcached_key $key;
memcached_pass $uri;
echo_location_async /json_available;
error_page 404 @proxy;
}
location /json_available {
echo_duplicate 1 "$arg_callback(";
echo_location_async "/json_memcached";
location ~* \.(json)$ {
default_type "application/json";
# enable xss, and use "callback"
xss_get on;
xss_callback_arg callback;
# get data from memcached, proxy if not found
set memcached_key $key;
memcached_pass $uri;
render :json => @something.to_json, :callback => params[:callback]
@something = Rails.cache.fetch("some_key") { Something.find("data") }
render :json => @something.to_json, :callback => params[:callback]
aoeu
@dylanz
dylanz / test.rb
Created February 22, 2011 19:54
test.rb
puts "lol"