This file contains hidden or 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 MonitorsDB do | |
@spec new_db() :: :ets.tid() | |
def new_db() do | |
random_string() | |
|> new_db() | |
end | |
@spec new_db(String.t()) :: :ets.tid() | |
def new_db(name) do | |
name |
This file contains hidden or 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 ExCluster.StateHandoff do | |
use GenServer | |
require Logger | |
def start_link(opts) do | |
GenServer.start_link(__MODULE__, opts, name: __MODULE__) | |
end | |
def child_spec(opts \\ []) do | |
%{ |
This file contains hidden or 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 RestartServer do | |
use GenServer | |
def start_link(args) do | |
GenServer.start_link(__MODULE__, args, [name: __MODULE__]) | |
end | |
def init(_) do | |
IO.puts("RESTARTING") | |
num = Enum.random(1..1_000_000) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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}", |