Skip to content

Instantly share code, notes, and snippets.

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: "[email protected]", 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")
$ ruby stacked_blocks.rb
START ARRAY THINGS
START ONE
START TWO
START THREE
START FOUR
IN THE MIDDLE OF ARRAYS DOING IT
FINISH FOUR
FINISH THREE
FINISH TWO
@hassox
hassox / debug
Last active August 29, 2015 14:08
struct(User, params) does not transfer values
09:52:35.045 request_id=oOTTwz6ywSK5RsianPnN [info] POST /users
RAW PARAMS
09:52:35.069 request_id=oOTTwz6ywSK5RsianPnN [debug] Processing by CloseBy.UserController.create
Accept: text/html
Parameters: %{"user" => %{"confirm_password" => "p", "email" => "[email protected]", "password" => "p"}}
%{"user" => %{"confirm_password" => "p", "email" => "[email protected]",
"password" => "p"}}
THE CREATE PARAMS params["user"]
%{"confirm_password" => "p", "email" => "[email protected]", "password" => "p"}
09:52:35.192 request_id=oOTTwz6ywSK5RsianPnN [info] Sent 422 in 147ms
@hassox
hassox / application_controller.ex
Created October 22, 2014 00:53
A first attempt at a usable user controller setup in Phoenix
defmodule CloseBy.ApplicationController do
defmacro __using__(_opts) do
quote do
use Phoenix.Controller
import CloseBy.ApplicationController
alias CloseBy.Router
end
end
end
@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