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 MyApp do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [ | |
dispatch: dispatch | |
]) |
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 Topological do | |
def sort(library) do | |
g = :digraph.new | |
Enum.each(library, fn {l,deps} -> | |
:digraph.add_vertex(g,l) # noop if library already added | |
Enum.each(deps, fn d -> add_dependency(g,l,d) end) | |
end) | |
if t = :digraph_utils.topsort(g) do | |
print_path(t) | |
else |
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 generate_pagination_links(%TripAdvisor{url: url}, page) do | |
ranges = | |
Floki.find(page, "#EATERY_LIST_CONTENTS .pageNumbers a") | |
# ["2", "3", "4", "5", "6", "40"] | |
|> Floki.attribute("data-page-number") | |
[pag_start | _] = ranges | |
pag_last = List.last(ranges) | |
{start, _} = Integer.parse(pag_start) | |
{last, _} = Integer.parse(pag_last) |
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 Test.Services.ReleasePollerTest do | |
use Test.DataCase, async: true | |
import Mimic | |
import Test.Factory | |
alias Test.Services.RPC | |
setup :verify_on_exit! | |
test "successfully started polling repository - no error" do |
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
iex(37)> :hackney_trace.disable() | |
:ok | |
iex(38)> :hackney_trace.enable(:max, :io) |
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 DockerApi.DockerfileParser do | |
@comment ~r/^\s*#/ | |
@continuation ~r/^.*\\\s*$/ | |
@instruction ~r/^\s*(\w+)\s+(.*)$/ | |
def parse(path) do | |
File.stream!(path) | |
|> Stream.map(fn line -> | |
parse_line(line) | |
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 DockerApi do | |
@version "v1.37" | |
@endpoint URI.encode_www_form("/var/run/docker.sock") | |
@protocol "http+unix" | |
def commit(container_id, payload) do | |
# commit image | |
{:ok, %{body: body}} = | |
HTTPoison.post( | |
"#{@protocol}://#{@endpoint}/#{@version}/commit?container=#{container_id}", |
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
creating | handling with | where y is | |
----------------------------------------------------- | |
raise x | rescue y | %RuntimeError{message: x} | |
error(x) | rescue y | %ErlangError{original: x} | |
throw x | catch y | x | |
exit(x) | catch :exit, y | x | |
creating | handling with | where y is | and z is |
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 MyList | |
def delete_all(list, el) do | |
_delete_all(list, el, []) | |
|> Enum.reverse() | |
end | |
def _delete_all([el | tail], el, new_list) do | |
_delete_all(tail, el, new_list) | |
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 ReqWithBackoff do | |
# hakney :connect_timeout - timeout used when establishing a connection, in milliseconds | |
# hakney :recv_timeout - timeout used when receiving from a connection, in milliseconds | |
# poison :timeout - timeout to establish a connection, in milliseconds | |
# :backoff_max - maximum backoff time, in milliseconds | |
# :backoff_factor - a backoff factor to apply between attempts, in milliseconds | |
defp fetch(uri) do | |
options = [ | |
follow_redirect: true, | |
recv_timeout: Application.get_env(:arc, :recv_timeout, 5_000), |