Skip to content

Instantly share code, notes, and snippets.

View cybrox's full-sized avatar
☠️
Tinkering

Sven Gehring cybrox

☠️
Tinkering
View GitHub Profile
@cybrox
cybrox / phx-ete2.ex
Last active March 20, 2019 15:59
phx-ete2.ex
if @env == :test do
forward("end-to-end", MyApp.Plug.TestEndToEnd)
end
@cybrox
cybrox / phx-ete1.ex
Created March 20, 2019 15:33
phx-ete1.ex
config :myapp, MyApp.Endpoint,
server: true
defp deps do
[
# NOTE: You would have to adjust this to your local path
{:rayman, path: "/Users/sgehring/development/blog/rayman"}
]
end
defmodule RaymanPlayground.Application do
@moduledoc false
use Application
def start(_type, _args) do
{:ok, pid} = :gen_tcp.listen(1883, [
:binary,
active: false,
reuseaddr: true
defmodule Rayman do
@moduledoc """
Rayman is a pure Elixir implementation of MQTT for educational purposes.
"""
def decode_packet(packet) do
IO.inspect packet
end
def encode_packet(data) do
@cybrox
cybrox / testing-protected-phoenix-controllers-4.ex
Created July 15, 2018 13:34
testing-protected-phoenix-controllers-4.ex
test "accessing a protected route" do
user = insert(:user, [username: "Sven"])
conn = conn |> get(user_path(conn, :show, "self") <> with_user(user))
# assert results
end
@cybrox
cybrox / testing-protected-phoenix-controllers-3.ex
Created July 15, 2018 13:33
testing-protected-phoenix-controllers-3.ex
@spec send_unauthorized_if_not_faked(Plug.Conn.t) :: Plug.Conn.t
if @env == :test do
defp send_unauthorized_if_not_faked(conn) do
conn |> append_testing_backdoor()
end
else
defp send_unauthorized_if_not_faked(conn) do
conn |> send_unauthorized_response()
end
end
@cybrox
cybrox / testing-protected-phoenix-controllers-2.ex
Created July 15, 2018 13:32
Blog: Testing Protected Phoenix Controllers - Snippet 2
if @env == :test do
defp send_unauthorized_if_not_faked(conn) do
# Implement testing backdoor
conn
end
else
defp send_unauthorized_if_not_faked(conn) do
send_unauthorized_response(conn)
end
end
@cybrox
cybrox / testing-protected-phoenix-controllers-1.ex
Created July 15, 2018 13:31
Blog: Testing Protected Phoenix Controllers - Snippet 1
def authenticate_user_token(conn, _opts) do
with ["Bearer " <> token] <- get_req_header(conn, "authorization"),
{:ok, %{:id => user_id}} <- Token.verify_user_for_token(token),
conn_assign_user_details(conn, user_id)
else
_ -> send_unauthorized_if_not_faked(conn)
end
end
@cybrox
cybrox / clean-docker.sh
Created June 8, 2018 08:03
Reclaim Disk Space from Docker
docker rm -v $(docker ps -f status=dead -f status=exited -aq)
docker rmi $(docker images --no-trunc -qf dangling=true)
docker volume rm $(docker volume ls -qf dangling=true)