Skip to content

Instantly share code, notes, and snippets.

View sescobb27's full-sized avatar
πŸ‡¨πŸ‡΄
sisas parce

Simon Escobar Benitez sescobb27

πŸ‡¨πŸ‡΄
sisas parce
View GitHub Profile
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
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
%{
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)
@sescobb27
sescobb27 / my_app.ex
Created February 6, 2019 18:11 — forked from alanpeabody/my_app.ex
Websockets in Elixir with Cowboy and Plug
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
])
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
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
iex(37)> :hackney_trace.disable()                                                                                                                                                
:ok                                                                                                                                                                              
iex(38)> :hackney_trace.enable(:max, :io)
@sescobb27
sescobb27 / docker_parser.ex
Last active September 12, 2018 18:20
simple Dockerfile parser, doesn't support complex RUN expressions with continuation (\)
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)
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}",