Skip to content

Instantly share code, notes, and snippets.

@0xSventek
0xSventek / js_sdk.js
Created October 27, 2011 16:40
Javascript SDK example
var facebook_tools = new function() {
this.init = function () {
if (FB.getSession() == null) {
this.login();
} else {
facebook_session = FB.getSession();
}
return this;
};
@0xSventek
0xSventek / project.rb
Created October 4, 2011 00:45
project
class Project < ActiveRecord::Base
def next
self.class.where("created_at > ?", self.created_at).order("created_at asc").first
end
def previous
self.class.where("created_at < ?", self.created_at).order("created_at desc").first
end
end
@0xSventek
0xSventek / projects_controller
Created October 4, 2011 00:38
projects_controller
class ProjectsController < ApplicationController
before_filter :get_base_project, :only => [:next,:previous]
before_filter :force_js_content_type, :only => [:next,:previous]
caches_action :next, :cache_path => proc{ |c| "/projects/" + (c.get_base_project.next.cache_key rescue "nil")}, :expires_in => 15.minutes
caches_action :previous, :cache_path => proc{ |c| "/projects/" + (c.get_base_project.previous.cache_key rescue "nil")}, :expires_in => 15.minutes
def next
@project = @base_project.next
@0xSventek
0xSventek / routes.rb
Created October 4, 2011 00:31
routes
get '/projects/:base_project_id/next', :to => 'projects#next', :as => :next_project
get '/projects/:base_project_id/previous', :to => 'projects#previous', :as => :previous_project