Skip to content

Instantly share code, notes, and snippets.

View orafaelfragoso's full-sized avatar
:octocat:
Working from home

Rafael Fragoso orafaelfragoso

:octocat:
Working from home
View GitHub Profile
@orafaelfragoso
orafaelfragoso / member.rb
Created March 20, 2014 15:30
Member e Roles
class Member < ActiveRecord::Base
has_many :roles
devise :database_authenticatable, :async, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
def manager?
(false if self.role == 0) || true
end
@orafaelfragoso
orafaelfragoso / ubuntu_14_04_passenger_nginx_fix.md
Last active August 29, 2015 14:01
Fix for Passenger + Nginx installation on Ubuntu 14.04

Install Nginx extras: sudo apt-get install nginx-extras

Install Nginx as root: rvmsudo passenger-install-nginx-module

This should let you install Nginx without errors.

I was running Ubuntu 14.04 64 bits with RVM

@orafaelfragoso
orafaelfragoso / aws-s3.rb
Last active August 29, 2015 14:02
Upload and delete files from Amazon S3
def upload_to_s3(file, file_name,file_path)
aws = AWS::S3.new
bucket = aws.buckets[ENV['S3_BUCKET_NAME']]
object = bucket.objects[file_name]
object.write(:file => file)
local_file = File.open(file_path)
File.delete(local_file)
end
def delete_from_s3
@orafaelfragoso
orafaelfragoso / nginx.conf
Last active August 29, 2015 14:04
Nginx Production Configuration
upstream unicorn {
server unix:/tmp/unicorn.carelinked.sock fail_timeout=0;
}
server {
listen 80 default_server;
client_max_body_size 4G;
root /home/USER/APP/current/public;
try_files $uri/index.html $uri @unicorn;
@orafaelfragoso
orafaelfragoso / sessions_controller.rb
Created August 1, 2014 03:41
Omniauth Controller Example
class SessionsController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
def create
# Find an identity here
identity_info = Identity.filter_auth_hash(auth_hash)
@identity = Identity.find_with_omniauth(identity_info)
if @identity.nil?
class Identity < ActiveRecord::Base
belongs_to :member
def self.find_with_omniauth(info)
find_by provider: info[:provider], uid: info[:uid]
end
def self.create_with_omniauth(info)
create(uid: info[:uid], provider: info[:provider], oauth_token: info[:oauth_token], oauth_expires_at: info[:oauth_expires_at], oauth_secret: info[:oauth_secret])
class Member < ActiveRecord::Base
has_many :identities
def self.create_with_omniauth(info)
# create(first_name: info[:first_name], last_name: info[:last_name], email: info[:email], gender: info[:gender], birthday: info[:birthday], nickname: info[:nickname], profile_picture: info[:profile_picture], location: info[:location])
member = find_or_initialize_by_email(info[:email]) do |i|
i.first_name = info[:first_name]
i.last_name = info[:last_name]
i.email = info[:email]
@orafaelfragoso
orafaelfragoso / routes.rb
Created August 1, 2014 03:47
Omniauth Routes
# Omniauth Authentication
get 'auth/:provider/callback' => 'sessions#create'
get 'auth/failure' => redirect('/')
get 'signout' => 'sessions#destroy', :as => 'signout'
@orafaelfragoso
orafaelfragoso / schema.rb
Created August 1, 2014 03:48
Schema for Omniauth and Devise
create_table "identities", force: true do |t|
t.integer "member_id"
t.string "uid"
t.string "provider"
t.string "oauth_token"
t.string "oauth_secret"
t.datetime "oauth_expires_at"
end
add_index "identities", ["member_id"], name: "index_identities_on_member_id", using: :btree
@orafaelfragoso
orafaelfragoso / unicorn
Created August 5, 2014 16:37
Unicorn upstart
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO