Guilherme Simões
Adds CDN support to the jquery-rails gem.
# app/views/layouts/application.html.erb
<%= javascript_include_tag "//ajax.googleapis.com/jquery.min.js" %>
<%= javascript_include_tag "application" %>
# app/views/layouts/application.html.erb
<%= jquery_include_tag :google %>
<%= javascript_include_tag "application" %>
Detects the user's preferred language sent in the "Accept-Language" HTTP header.
request.env["HTTP_ACCEPT_LANGUAGE"]
# => en-GB,en;q=0.8,en-US;q=0.6,pt-PT;q=0.4,pt;q=0.2
http_accept_language.user_preferred_languages
# => ["en-GB", "en", "en-US", "pt-PT", "pt"]
available = I18n.available_locales
# => [:en, :pt]
http_accept_language.preferred_language_from(available)
# => "en"
Finds the size or type of an image given its URL by fetching as little as needed.
FastImage.size("http://fake.url/funny.gif")
# => [300, 50] # width, height
FastImage.type("http://fake.url/png-image-with-no-extension")
# => :png
FastImage.size("http://fake.url/large-image-that-causes-DOS.jpg",
raise_on_failure: true, timeout: 0.5)
# => FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
Provides a standardized interface to many different authentication providers such as Facebook and OpenID. Also supports a traditional strategy using username and password.
use OmniAuth::Builder do
provider :github, "GITHUB_KEY", "GITHUB_SECRET"
end
# some_view.html.erb
<%= link_to "Login with GitHub", "/auth/github" %>
get "/auth/:provider/callback" do
omniauth = env["omniauth.auth"]
raise omniauth.to_yaml
end
provider: "github"
uid: "531168"
info:
nickname: "GuilhermeSimoes"
email: "guilherme.rdems@gmail.com"
name: "Guilherme Simões"
image: "https://secure.gravatar.com/avatar/480fec4ec9bf207c739b4bd38ea98aec?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"
urls:
GitHub: "https://github.com/GuilhermeSimoes"
extra:
get "/auth/failure" do
flash[:notice] = params[:message]
redirect_to "/you-suck-for-not-logging-in-with-GitHub"
end
Helps configure Rails apps, especially open source Rails apps.
$ rails generate figaro:install
# Creates a YAML config file and adds it to .gitignore
# config/application.yml
HELLO: "world"
development:
HELLO: "developers"
production:
HELLO: "users"
# config/environments/development.rb
config.action_mailer.default_url_options = {
host: "localhost:3000"
}
# config/environments/production.rb
config.action_mailer.default_url_options = {
host: "example.com"
}
# config/application.rb
config.action_mailer.default_url_options = {
host: ENV["MAILER_HOST"]
}
# config/environments/production.rb
config.action_mailer.smtp_settings = {
user_name: ENV["EMAIL_USER_NAME"],
password: ENV["EMAIL_PASSWORD"]
}
# config/application.yml
MAILER_HOST: "localhost:3000"
production:
MAILER_HOST: "example.com"
EMAIL_PASSWORD: "super-difficult-password"
EMAIL_USER_NAME: "admin"
# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"]
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"]
provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"]
end
# config/initializers/secret_token.rb
YourApp::Application.config.secret_token = ENV["SECRET_TOKEN"]
$ heroku config:set S3_KEY=totallyrandomstring
$ heroku config:set S3_SECRET=classified
$ heroku config:set PUSHER_KEY=nopenopenopenopenope
$ heroku config:set PUSHER_SECRET=topsecret
$ heroku config:set PUSHER_APP_ID=imoutoffunnyideas
...
$ rake figaro:heroku
# One command to push ENV variables to Heroku