Skip to content

Instantly share code, notes, and snippets.

View cgallagher's full-sized avatar

Chris Gallagher cgallagher

View GitHub Profile
@cgallagher
cgallagher / ugc_publish_action.rb
Created April 19, 2012 09:31
Pubish a UGC Image via Bookface
def publish!(fbid, key, shwop=nil, entry=nil)
fb_action = Facebookaction.find_by_key(key)
access_token = Bookface::Base.client_credentials
a_type = fb_action.action_type
url = "http://#{Settings.host_url}/actions/#{fb_action.key}"
if entry.width > 520 and entry.height > 520
puts "image is big enough for user generated attachment"
params = { Settings.facebook.fb_object_ref => url,
"image[0][url]" => entry.entry_asset_url,
@cgallagher
cgallagher / scroll_top.js
Created March 28, 2012 09:07
Animate scroll top within FB iFrame
function scroll_to_top() {
FB.Canvas.getPageInfo(function (pageInfo) {
var iframe_scroll_y = pageInfo.scrollTop;
var target_div_y = $('#dr_dre').position().top;
if (iframe_scroll_y > target_div_y) {
var animOptions = {
step: function () {
FB.Canvas.scrollTo(0, this.y);
},
@cgallagher
cgallagher / paperclip_s3_url_rewriter.rb
Created August 30, 2011 13:05
A piece of code that will help paperclip to detect if the user is browsing your app in HTTPS and serve up S3 Images over the corresponding protocol.
#create this file in app/middleware and then in config/application.rb at the beginning of the application class you need to call it "config.middleware.use "PaperclipS3UrlRewriter"
class PaperclipS3UrlRewriter
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
if response.is_a?(ActionController::Response) && response.request.protocol == 'https://' && headers["Content-Type"].include?("text/html")
@cgallagher
cgallagher / ses.rb
Created March 28, 2011 14:03
Send Emails from db to multiple users via Amazon SES
class MailshotController < ApplicationController
def init
due_emails = EmailQueue.find(:all, :conditions => ["scheduled_at < ? AND is_complete = ?", DateTime.now, false])
for email in due_emails
users = get_users_by_locale(email.locale)
user_emails = get_user_emails(users)
options = {
:from => email.from_email_address,
:to => user_emails,
@cgallagher
cgallagher / get_friends.js
Created March 15, 2011 11:41
get facebook friends
get_friend_list: function(facebook_id, limit, order, callback)
{
var friends = FB.Data.query("SELECT first_name, pic_square, uid, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY {1} LIMIT {2}", parseInt(facebook_id), order, limit);
friends.wait(function(friends){
callback(friends);
});
},
@cgallagher
cgallagher / fb_wallpost_with_js_sdk.js
Created March 11, 2011 11:46
Create a wallpost for a target user using the FB JavaScript SDK
send_wall_post_to_user: function(idx, facebook_id, message, user_message, post_name, post_description, post_image, post_caption)
{
var params = {};
params['message'] = user_message;
params['name'] = post_name;
params['description'] = post_description;
params['link'] = 'http://apps.facebook.com/irelandville_dev/';
params['picture'] = post_image;
params['caption'] = post_caption;
@cgallagher
cgallagher / FB Feed Form
Created March 2, 2011 09:19
Generate a simple feed form using the Facebook JavaScript SDK
show_feed_form: function(share_message,share_name, share_caption, share_description, share_image_href, share_image_src, share_action_link_text, share_action_link_href, share_user_message_prompt, share_href, callback)
{
var publish = {
method: 'stream.publish',
message: "",
attachment: {
name: share_name,
caption: share_caption,
description: (
/*
$("#prev ~ sibling) doesnt seem to work in IE7 if the type both the prev and sibling element are of the same type. The examples on jQuery.com dont point this out.
(http://docs.jquery.com/Selectors/siblings#prevsiblings)
below is a workaround.
*/
# template.rb
# USAGE: rails -m http://gist.github.com/gists/115163.txt PROJECT_NAME
run "rm public/index.html"
plugin 'thinking_sphinx', :git => 'git://github.com/freelancing-god/thinking-sphinx.git'
plugin 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git'
plugin 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl.git'
plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
plugin 'project_search', :git => 'git://github.com/37signals/project_search.git'
plugin 'hubahuba', :git => 'git://github.com/paulca/hubahuba.git'
@cgallagher
cgallagher / format_number_to_thousands.rb
Created November 4, 2009 16:27
Takes a flat number and uses a regex to format the commas
def self.formatViews(number)
number = number.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,')
number
end