This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def millis-in-year (* 1000 60 60 24 365)) | |
(defn serve-vodka [user-id] | |
(let [user (user/find-by-id user-id) | |
millis-since-born (- (System/currentTimeMillis) (:birthtime user)) | |
years-since-born (/ millis-since-born millis-in-year)] | |
(if (>= years-since-born 21) | |
"Here's your vodka!" | |
"Too Young!"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def doit(x) | |
if x < 1 | |
10 / x | |
else | |
x + 1 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app_1 | connecting to rabbitmq (attempt 1) | |
app_1 | connecting to rabbitmq (attempt 2) | |
app_1 | connecting to rabbitmq (attempt 3) | |
app_1 | connected! | |
app_1 | 2018-06-14 13:47:42 +0000 received message: hello | redelivered: false | first try, rejecting with requeue=true | |
app_1 | 2018-06-14 13:47:42 +0000 received message: hello | redelivered: true | already retried, rejecting with retry=false | |
app_1 | 2018-06-14 13:47:47 +0000 Bye |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws s3 ls $S3_FILE_URL | awk '{print $1 " " $2}' | xargs -I {} gdate --date="{}" +%s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plug.Validator do | |
def init(opts), do: opts | |
def call(conn, opts) do | |
case conn.private[:validate] do | |
nil -> conn | |
validations -> validate(Conn.fetch_query_params(conn), validations, opts[:on_error]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plug.Validator do | |
def init(opts), do: opts | |
def call(conn, opts), do: conn | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plug.ValidatorTest do | |
use ExUnit.Case | |
use Plug.Test | |
@subject Plug.Support.Router | |
@opts @subject.init([]) | |
def assert_json_response(request_url, expected_status, expected_body) do | |
conn = conn(:get, request_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code.load_file("test/support/validators.exs") | |
Code.load_file("test/support/router.exs") | |
ExUnit.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plug.Support.Validators do | |
import Plug.Conn | |
def validate_integer(v) do | |
case Integer.parse(v) do | |
:error -> {:error, "could not parse #{v} as integer"} | |
other -> other | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plug.Support.Router do | |
import Plug.Conn | |
use Plug.Router | |
import Plug.Support.Validators, | |
only: [validate_integer: 1, validate_boolean: 1, on_error_fn: 2, json_resp: 3] | |
plug :match | |
plug Plug.Validator, on_error: &on_error_fn/2 | |
plug :dispatch |