Skip to content

Instantly share code, notes, and snippets.

Warden::Strategies.add(:bcrypt) do
def valid?
params[:username] || params[:password]
end
def authenticate!
return fail! unless user = User.first(:username => params[:username])
if user.encrypted_password == params[:password]
success!(user)
Object.prototype.autoload = function(type, filePath, includeAsType){
var obj = undefined;
if(includeAsType === undefined) includeAsType = true;
this.__defineGetter__(type, function(){
if(!obj){
obj = require(filePath);
if(includeAsType) obj = obj[type];
}
return obj;

Keybase proof

I hereby claim:

  • I am hassox on github.
  • I am hassox (https://keybase.io/hassox) on keybase.
  • I have a public key ASB5a6LRY3Gb3-ZtU3F1NEyhxccQsiERk0td44Jtj0iAugo

To claim this, I am signing this object:

@hassox
hassox / devise_initializer.rb
Last active July 20, 2016 01:54
devise jwtable
Devise.setup do |config|
config.warden do |manager|
manager.intercept_401 = false
manager.default_strategies(scope: :user).unshift :jwtable
end
end
@hassox
hassox / auth.ex
Last active May 24, 2016 20:57 — forked from Devalo/auth.ex
Auth. When registering a new user, it checks if password and email is correct, and invoke login/2 which assigns :current_user and pipes through Guardian.Plug.sign_in. It raises error when using @current_user in views, saying assign @current_user not available in eex template.
defmodule Cvapp.Auth do
import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0]
import Plug.Conn
def login(conn, user) do
conn
|> assign(:current_user, user)
|> Guardian.Plug.sign_in(user, :access)
end
@hassox
hassox / Test
Last active November 19, 2015 23:20 — forked from faizaanshamsi/Test
@also_valid_attrs %{email: "fas@nd.com", role: "client", is_financial_professional: true, password: "password"}
setup do
changeset = User.changeset(%User{}, @also_valid_attrs)
user = Repo.insert! changeset
{ :ok, jwt, full_claims } = Guardian.Plug.encode_and_sign(user, :api)
conn = conn()
|> put_req_header("accept", "application/vnd.api+json")
@hassox
hassox / benchmark.rb
Created August 30, 2012 23:28 — forked from jnicklas/benchmark.rb
Hash access speed with strings/vs symbols
require "benchmark"
hash = {'key' => 1, :key => 2}
n = 5_000_000
Benchmark.bm do |x|
x.report("strings") { n.times { hash['key'] } }
x.report("symbols") { n.times { hash[:key] } }
x.report("strings, set") { n.times { hash['key'] = 1 } }
@hassox
hassox / lazy_attributes.rb
Created August 14, 2012 19:14
Quick lazy attribute concern
module Concerns
# Wraps methods to provide lazy attribute evaluation
# If a value evaluates to a proc, the proc is called, and the value
# is returned
#
# @example
# class Foo
# include Concerns::LazyAttributes
#
# attr_accessor :bar
" hint to keep lines short
if exists('+colorcolumn')
set colorcolumn=80
endif
function thisIsATest(){
return true;
}