Skip to content

Instantly share code, notes, and snippets.

View cgallagher's full-sized avatar

Chris Gallagher cgallagher

View GitHub Profile
@cgallagher
cgallagher / is_mobile.js
Created July 9, 2012 15:44
Check if user is mobile with JavaScript.
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i) ? true : false;
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
},
@cgallagher
cgallagher / 34B489.rb
Created July 3, 2012 15:52
Script for pushing out loads of actions in order to see how your Open Graph actions scale out.
require 'rubygems'
require "net/http"
require "net/https"
require "uri"
access_token = "" #App Access Token (app_id|app_secret)
user_id = "" #FBID of an app user who has granted perms to publish actions within your app
og_object_url = "http://dby-staging.herokuapp.com/og/84" #url to the OG data to be pushed along with your user
@cgallagher
cgallagher / restrict_addresses.rb
Created July 2, 2012 12:08
Rack Middleware to block IP addresses to active_admin
class RestrictAddresses
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
incoming_ip_address = request.env['REMOTE_ADDR']
allowed_range = ['127.0.0.1']
@cgallagher
cgallagher / nukehomebrew.sh
Created June 25, 2012 11:06
Completely kill homebrew
cd `brew --prefix`
rm -rf Cellar
brew prune
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
@cgallagher
cgallagher / milestone.rb
Created June 13, 2012 10:28
Active Admin Image Upload Form
ActiveAdmin.register Milestone do
scope :all, :default => true
scope :global
scope :user_specific
index do
column :title
column :description
column :required_litres
column :is_active
@cgallagher
cgallagher / match_friends.rb
Created June 12, 2012 11:40
Match friends who are also using an app and see if they are also installed in the db.
def match_friends
# now just find the friends of the user who are also using the app.
begin
res = Bookface::Graph.request("fql", { :q=> "SELECT uid, name, pic_square FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())", :access_token => access_token })
rescue
res = nil
end
friend_ids = []
# retrieve friend list from graph and compile a list of friends who are registered - aww friend
unless res.nil? or res["data"].nil?
@cgallagher
cgallagher / og.rb
Created June 11, 2012 10:05
OG Endpoint
def show
if request.user_agent.index('facebookexternalhit')
@thing = Thing.find(params[:id])
add_meta :property => 'og:title', :content => @thing.title
add_meta :property => 'og:type', :content => "article"
add_meta :property => 'og:url', :content => @thing.url_to_the_content
add_meta {{:property => 'og:image', :content => @thing.image_url}}
end
end
@cgallagher
cgallagher / davos.rb
Created May 3, 2012 11:40
Basic insert text on image via imagemagick
class Davos
#require 'RMagick'
include Magick
def self.for(user, message)
bottle_composition = create_composition(user, message)
bottle_file = Tempfile.new("composite-for-#{user.fbid}.jpg")
bottle_composition.write(bottle_file.path)
@cgallagher
cgallagher / action.rb
Created May 3, 2012 11:45
Basic FB Action
class Fbaction < ActiveRecord::Base
class << self
def publish!(fbid)
url = url + "/#{entry.id}"
params = { "<object_ref_here>" => url,
:access_token => access_token
}
res = Bookface::Graph.request("#{fbid}/<namespace_here>:<action_name_here>", params, :method => :post)
end
# application.rb
def user_is_safari_fucked?
BPLogger.debug(request.env['HTTP_USER_AGENT'])
request.env['HTTP_USER_AGENT'].match(/(AppleWebKit).+Version\/(5\.1\.[4-9])/)
end
def js_redirect_to(url, signed_request=nil)