Skip to content

Instantly share code, notes, and snippets.

@heaven
heaven / token.rb
Created May 19, 2019 17:03 — forked from GregBaugues/token.rb
Google API OAuth 2.0 refresh token (Ruby on Rails)
# The OAuth access token provided by the Google API expires in 60 minutes. After expiration,
# you must exchange a refresh token for a new access token. Unfortunately, the the Google API
# ruby gem does not include a method for refreshing access tokens.
# You can read up on how to refresh an access token here:
# https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
# This Token model implements that process. It's based off of a Token model that can be created
# by running:
# rails g model Token token:text refresh_token:string expires_at:datetime
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@heaven
heaven / ajax-chosen.js
Created July 21, 2012 07:55
Ajax support for chosen
new function($) {
return $.fn.ajaxChosen = function(options, callback) {
var select = this,
chosen;
select.chosen();
chosen = select.data('chosen');
var val,
timeout = null,
def errors_report
return nil unless self.source.present?
# self.source — the paperclip attachment
book = Spreadsheet.open(self.source.path)
sheet = book.worksheet(0)
errors = self.import_errors.map { |e| e[:line] }
path = "tmp/#{self.source.original_filename}-errors.xls"