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
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])
@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?
@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 / 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 / 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 / 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
.highlight{background-color:#073642;color:#93a1a1}.highlight .c{color:#586e75 !important;font-style:italic !important}.highlight .cm{color:#586e75 !important;font-style:italic !important}.highlight .cp{color:#586e75 !important;font-style:italic !important}.highlight .c1{color:#586e75 !important;font-style:italic !important}.highlight .cs{color:#586e75 !important;font-weight:bold !important;font-style:italic !important}.highlight .err{color:#dc322f !important;background:none !important}.highlight .k{color:#cb4b16 !important}.highlight .o{color:#93a1a1 !important;font-weight:bold !important}.highlight .p{color:#93a1a1 !important}.highlight .ow{color:#2aa198 !important;font-weight:bold !important}.highlight .gd{color:#93a1a1 !important;background-color:#372c34 !important;display:inline-block}.highlight .gd .x{color:#93a1a1 !important;background-color:#4d2d33 !important;display:inline-block}.highlight .ge{color:#93a1a1 !important;font-style:italic !important}.highlight .gr{color:#aa0000}.highlight .gh{color:#586e
@orafaelfragoso
orafaelfragoso / .bash_profile
Last active December 18, 2015 03:19
My new Bash Profile style.
# MySQL Path
export PATH=/usr/local/mysql/bin:$PATH
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# Colors
@orafaelfragoso
orafaelfragoso / form.html
Created May 14, 2013 23:10
jQuery code to validate input fields
<form id="uploadImages">
<input type="file" id="fotos" multiple="true" /><br />
<p class="callback">Try to upload some files here.</p>
<input type="submit" name="Submit" />
</form>
@orafaelfragoso
orafaelfragoso / README.markdown
Created November 9, 2012 20:24 — forked from greypants/README.markdown
RAILS 3: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.