Skip to content

Instantly share code, notes, and snippets.

View kineticac's full-sized avatar

Arthur Chang kineticac

View GitHub Profile
# users_controller.rb
@teams = cache_fetch("teams"){
Team.find(:all)
}
curl -d "game_id=107763&access_token=YOUR_ACCESS_TOKEN" https://api.fanvibe.com/v1/checkin
[{"checkin":{"id":9021,"game_id":107763,"user_id":1018}}]
<div id="olark-data"><a class="olark-key" id="YOUR_OLARK_KEY" title="Powered by Olark" href="http://olark.com/about" rel="nofollow">Powered by Olark</a></div>
<head>
<!-- ... other head code here -->
<%= yield :javascript_include_tags %>
<%= render :partial => '/shared/olark_script' %>
</head>
<body>
<!-- ... body code here -->
<%= render :partial => '/shared/olark' %>
</body>
## fixes mobile_fu :mobile formats with restful_authentication
def access_denied
respond_to do |format|
# format.html do # this will not work with mobile_fu
format.any(:html, :mobile) do
store_location
redirect_to login_path
end
format.any(:json, :xml) do
@kineticac
kineticac / .gems
Created September 24, 2010 01:39
mislav-will_paginate -s http://gems.github.com
libxml-ruby
rest-client -s http://gems.github.com
plist
aws-s3
htmlentities
paperclip
wireframe-apn_on_rails
configatron
geokit
@kineticac
kineticac / Example of a "cron" delayed_job
Created November 17, 2010 20:45
Here's a quick way to run a delayed_job job like a cron job. The ensure block is the key to making sure it runs again.
class SampleJob
def perform
begin
# do all your work in the begin block.
puts "hello world"
rescue Exception => e
# rescue any errors so that you know something went wrong. Email yourself the error if you need.
error_msg = "#{Time.now} ERROR (SampleJob#perform): #{e.message} - (#{e.class})\n#{(e.backtrace or []).join("\n")}"
puts error_msg
ensure
@kineticac
kineticac / authentications_controller.rb
Created March 9, 2011 09:25
Ryan Bates' AuthenticationsController
# these lines of code does not take into account a facebook token if the user is already connected
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
@kineticac
kineticac / authentications_controller.rb
Created March 9, 2011 09:27
New way of applying omniauth to an existing user
elsif current_user
current_user.apply_omniauth!(omniauth)
flash[:notice] = "Authentication successful."
redirect_to authentications_url