Skip to content

Instantly share code, notes, and snippets.

View cleitonfco's full-sized avatar

Cleiton Francisco cleitonfco

View GitHub Profile
@danielpowell4
danielpowell4 / google_sheet_report_writer.rb
Last active November 15, 2023 11:37
Write reports straight to google sheets! We use this in our Rails app to run queries and share the data outside the app.
require 'google/apis/sheets_v4'
require 'google/apis/drive_v3'
require 'googleauth'
require 'fileutils'
class GoogleSheetReportWriter
def initialize(notification_email:)
@creds = build_credentials
@notification_email = notification_email
end
@JoshCheek
JoshCheek / Readme.md
Last active June 20, 2018 07:55
Decrypting a Rails (v4.2.0) session

How to get the values

Salts

$ rails runner 'Rails.application.config.action_dispatch.tap { |c| p encrypted_cookie_salt: c.encrypted_cookie_salt, encrypted_signed_cookie_salt: c.encrypted_signed_cookie_salt }'

Secret Key Base

@squiter
squiter / followings.rb
Created February 5, 2014 21:27
Followers in Rails
class Followings < ActiveRecord::Base
attr_accessible :user_id, :follower_id
belongs_to :user
belongs_to :follower, class_name: 'User'
belongs_to :following, class_name: 'User', foreign_key: :user_id
validates_uniqueness_of :user_id, scope: :follower_id
end
@fernandoalmeida
fernandoalmeida / application_controller.rb
Last active March 7, 2022 01:23
Rails multi-tenant / multi-database with subdomains using database.yml
before_filter :select_database
def select_database
if Rails.env == "production"
unless request.subdomain.empty?
begin
subdomain = request.subdomains.first
config = ActiveRecord::Base.configurations[subdomain]
if config
ActiveRecord::Base.establish_connection(config)
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],