Skip to content

Instantly share code, notes, and snippets.

@brentsowers1
brentsowers1 / db_migrate
Created March 6, 2014 02:19
script/db_migrate to run migrations in deployed WAR files
require 'rubygems'
require 'active_record'
require 'yaml'
config = YAML::load(File.open(File.expand_path('../../config/database.yml', __FILE__)))
ActiveRecord::Base.establish_connection(config["production"])
ActiveRecord::Migrator.migrate(File.expand_path('../../db/migrate', __FILE__) )
@brentsowers1
brentsowers1 / facebooker2.rb
Created March 6, 2014 02:27
config/initializers/facebooker2.rb for running Facebooker apps
Facebooker2.load_facebooker_yaml
@brentsowers1
brentsowers1 / ApplicationController.rb
Created March 6, 2014 02:29
ApplicationController.rb for Facebooker apps
class ApplicationController < ActionController::Base
include Facebooker2::Rails::Controller
# Needed to support IE 6 and 7
before_filter :set_p3p_header_for_third_party_cookies
# Add an :except here if you have controllers that you want to
# allow non-users to access
before_filter :ensure_application_is_installed
@brentsowers1
brentsowers1 / facebooker_example.rb
Created March 6, 2014 02:30
Example of using Facebooker
# Unique Facebook ID of this user
facebook_id = current_facebook_user.id
# The OAuth token, this is how you access the user at a later point
token = current_facebook_client.access_token
# OAuth token expiration. Save this off, you'll need this to recreate
# the user later
expiration = current_facebook_client.expiration.to_i
name = current_facebook_user.name
# Gets an array of Mogil::Users
@brentsowers1
brentsowers1 / application_helper.rb
Created March 6, 2014 02:31
application_helper to include Facebooker
require 'lib/facebooker-1.0.69/lib/facebooker/rails/helpers/stream_publish'
require 'lib/facebooker-1.0.69/lib/facebooker/rails/helpers/fb_connect'
require 'lib/facebooker-1.0.69/lib/facebooker/rails/helpers'
require 'lib/facebooker-1.0.69/lib/facebooker/rails/facebook_form_builder'
module ApplicationHelper
include Facebooker::Rails::Helpers
...
end
@brentsowers1
brentsowers1 / helpers.rb
Created March 6, 2014 02:33
/lib/facebooker/rails/helpers.rb
module Facebooker
def self.api_key
unless @_api_key
config = (YAML.load(ERB.new(File.read(File.join(::Rails.root,"config","facebooker.yml"))).result)[::Rails.env])
@_api_key = config["api_key"]
end
@_api_key
end
@brentsowers1
brentsowers1 / publish_to_wall.rb
Created March 6, 2014 02:34
Publishing to a users wall with Facebooker
# load access token and expiration from database
client = Mogli::Client.new(access_token, expiration)
user = Mogli::User.find(facebook_id, client)
post = {:name => "main title for the post",
:caption => "Sub title for the post",
:description => "Long description for the post",
:picture => "url to a picture for the post",
:link => "url to go to when the user clicks on the title",
:from => {:name => "Your app's name",
:category => "Your app's category",
@brentsowers1
brentsowers1 / verify_facebook_sig.rb
Created March 6, 2014 02:36
Verifying Facebook's sig
require 'openssl'
require 'base64'
require 'json'
# Facebook's base64 algorithm is a special "URL" version of the algorithm.
def base64_url_decode(str)
str += '=' * (4 - str.length.modulo(4))
Base64.decode64(str.tr('-_','+/'))
end
@brentsowers1
brentsowers1 / ExecuteCommands.scala
Created March 6, 2014 02:38
Executing system commands in Scala
import sbt._
val output : String = Process("command to run").!!
val returnCode: Int = Process("command to run").!
@brentsowers1
brentsowers1 / build.sbt
Created March 6, 2014 02:39
build.sbt for Lift JSON
// 2.4 is currently the latest but will only work with Scala 2.9
val liftJson = "net.liftweb" %% "lift-json" % "2.3"