Skip to content

Instantly share code, notes, and snippets.

View ouranos's full-sized avatar

Olivier Brisse ouranos

View GitHub Profile
# lib/strategies/authentication_token_strategy.rb
class AuthenticationTokenStrategy < ::Warden::Strategies::Base
def valid?
authentication_token
end
def authenticate!
user = User.find_by_authentication_token(authentication_token)
user.nil? ? fail!('strategies.authentication_token.failed') : success!(user)
end
# config/application.rb
# Add Warden in the middleware stack
config.middleware.insert_after ActionDispatch::Flash, Warden::Manager do |manager|
manager.default_strategies :authentication_token
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::API
include WardenHelper
end
# config/application.rb
config.middleware.insert_after ActionDispatch::Flash, Warden::Manager do |manager|
manager.default_strategies :authentication_token
manager.failure_app = UnauthorizedController
end
# config/application.rb
config.middleware.insert_after ActionDispatch::Flash, Warden::Manager do |manager|
manager.default_strategies :authentication_token, :basic_auth
manager.failure_app = UnauthorizedController
end
@ouranos
ouranos / bio_brief.md
Last active April 20, 2016 02:19
BIO Migration Brief
∫ ruby serialize_bench.rb
Rehearsal -------------------------------------------
json 0.170000 0.010000 0.180000 ( 0.174912)
yaml 6.350000 0.000000 6.350000 ( 6.353721)
marshal 0.170000 0.000000 0.170000 ( 0.171184)
bson 0.210000 0.000000 0.210000 ( 0.213753)
yajl 0.130000 0.000000 0.130000 ( 0.130591)
oj 0.080000 0.000000 0.080000 ( 0.075798)
eval 0.370000 0.000000 0.370000 ( 0.370350)
---------------------------------- total: 7.490000sec
@ouranos
ouranos / .editorconfig
Last active July 1, 2016 04:34
Global editor config
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
@ouranos
ouranos / .editorconfig
Created July 1, 2016 04:34
Global editor config
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
@ouranos
ouranos / benchmark_results.rb
Last active May 30, 2017 05:11 — forked from havenwood/benchmark_results.rb
Benchmarking serialization speed of YAML, JSON, Marshal, and MessagePack in Ruby, JRuby, and Rubinius
# ruby 2.3.3p222
user system total real
YAML 31.860000 0.000000 31.860000 ( 31.886926)
JSON 1.370000 0.000000 1.370000 ( 1.374081)
Marshal 0.710000 0.000000 0.710000 ( 0.711384)
MessagePack 0.510000 0.000000 0.510000 ( 0.505674)
# jruby 9.1.7.0 (2.3.1)
user system total real
YAML 26.270000 0.040000 26.310000 ( 25.652204)