Skip to content

Instantly share code, notes, and snippets.

@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 / gist:1350518
Created November 9, 2011 05:35 — forked from nicholasf/gist:1350482
Seeking feedback before I post this

How to calculate an hourly rate.

Hi,

I've been watching job boards for Ruby related contracts lately and have noticed some low rates being offered with high expectations. It's happening frequently enough that I wanted to post my understanding of how to calculate an hourly rate. Setting reasonable standards of pay for the appropriate level of expertise is vital. There's a lot to say on the matter, so I've tried to be brief.

For some reason it's very easy for software developers to match their experience and knowledge to a full-time rate, but for contracting there is less awareness.

The difference between full-time employment and self employment.

@hassox
hassox / gist:659298
Created November 2, 2010 06:08 — forked from ngw/gist:659296
Rails.configuration.middleware.use Warden::Manager do |config|
config.failure_app = SessionsController
config.default_strategies :facebook
end
Warden::Manager.serialize_into_session do |user|
user.id.to_s
end
Warden::Manager.serialize_from_session do |id|
class BaseParticipant
include Ruote::LocalParticipant
def consume( workitem )
@workitem = workitem
begin
_, method, *args = workitem.fields['command'].split('/')
if arg
send( method, *args )
else
b = lambda {
:IMA_B_LOL
}
# A must enclose B
a = lambda {
b.call()
}
b.call() # raises nothing
class Guard < Padrino::Application
register Padrino::Helpers
require 'sass/plugin/rack'
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# What is the best way to get it to put out a, b, c
# without erroring about the superclass. The module
# inclusion order should not matter. In other words,
# I should be able to include A then B or B then A
# and either way all the letters a, b, and c are
# printed out (though not necessarily in that exact order)
module TopLevel
def foo(*args)
# do nothing
require 'rubygems'
require 'mq'
class ConnectionManager
@@current_connection = :default
@@alternative_connections = [:default, :default1, :default2]
def self.connections(type = :deafult)
# To connect to different nodes, have a configuration hash
# that matches the type, and use that for differnt connections