Skip to content

Instantly share code, notes, and snippets.

View kineticac's full-sized avatar

Arthur Chang kineticac

View GitHub Profile
@kineticac
kineticac / Rakefile
Created March 17, 2011 08:36
Include resque/tasks for running resque worker on dotcloud
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'resque/tasks'
Feedtopic::Application.load_tasks
@kineticac
kineticac / postinstall
Created March 17, 2011 08:34
This file is used on dotcloud and automatically called after you push code. This is used to select the correct supervisord.conf files we've made at the app root level.
#!/bin/sh
ln -s supervisord.conf_$(hostname) supervisord.conf
@kineticac
kineticac / supervisord.conf_namespace.scheduler
Created March 17, 2011 08:32
This is the supervisord.conf file for resque-schedulers on dotcloud
[program:scheduler]
command = rake resque:scheduler
environment = QUEUE=*
directory = /home/dotcloud/current/
@kineticac
kineticac / supervisord.conf_namespace.resque
Created March 17, 2011 08:30
The resque worker supervisord config on dotcloud
[program:resque]
command = rake resque:work
environment = QUEUE=*,RAILS_ENV=production
directory = /home/dotcloud/current/
@kineticac
kineticac / database.yml
Created March 17, 2011 08:18
Example of feedtopic.com's database yml file with a few obvious concealed information
production:
adapter: postgresql
encoding: unicode
database: feedtopic
pool: 5
username: x
password: "some|password"
port: 1200
host: db.feedtopicrules.dotcloud.com
@kineticac
kineticac / user.rb
Created March 9, 2011 09:28
A good way to create the authentication for Facebook
def apply_omniauth(omniauth, save_it = false)
case omniauth['provider']
when 'facebook'
self.apply_facebook(omniauth)
end
self.email = omniauth['user_info']['email'] if email.blank?
build_authentications(omniauth, save_it)
end
def build_authentications(omniauth, save_it = false)
@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
@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 / 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 / .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