Skip to content

Instantly share code, notes, and snippets.

Tymon Tobolski teamon

Block or report user

Report or block teamon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@teamon
teamon / Dockerfile
Created Aug 31, 2018
elixir + phoenix + node dockerfile
View Dockerfile
########################################
# 1. Build nodejs frontend
########################################
FROM node:10.9-alpine as build-node
# prepare build dir
RUN mkdir -p /app/assets
WORKDIR /app
# set build ENV
View twin.ex
defmodule Twin do
@moduledoc """
See http://teamon.eu/2017/different-approach-to-elixir-mocks-doubles/
"""
## PROXY
defmodule Proxy do
def unquote(:"$handle_undefined_function")(fun, args) do
[{__MODULE__, mod} | rest] = Enum.reverse(args)
View with_fallback.ex
defmodule Test do
def run(x) do
with :error <- try_one(x),
:error <- try_two(x),
:error <- try_three(x) do
:error
end
end
defp try_one(1), do: {:ok, "one"}
View mix_xref.txt
⌘ ~/code/tesla (master) λ mix xref graph
lib/tesla.ex
├── lib/tesla/adapter/hackney.ex (compile)
│ ├── lib/tesla/multipart.ex (compile)
│ └── lib/tesla.ex
├── lib/tesla/adapter/httpc.ex (compile)
│ ├── lib/tesla/adapter/shared.ex (compile)
│ ├── lib/tesla/multipart.ex (compile)
│ └── lib/tesla.ex
├── lib/tesla/adapter/ibrowse.ex (compile)
@teamon
teamon / httpd.erl
Created Oct 7, 2017
HTTP 1.0 web server in Erlang with persistent connections (Connection: keep-alive)
View httpd.erl
#!/usr/bin/env escript
%% Original author - Steve Vinoski <vinoski@ieee.org>
%% Modifications by - Tymon Tobolski <i@teamon.eu>
%% This is a modified version of https://gist.github.com/vinoski/4996859
%% with support for keeping TCP connection open.
%% Useful for testing HTTP clients and their Connection: keep-alive support
%% Usage: ./httpd.erl [PORT]
@teamon
teamon / decompile.escript
Created Sep 21, 2017
Decomile BEAM (erlang, elixir) into erlang with syntax highlighting
View decompile.escript
#!/usr/bin/env escript
% -*- mode: erlang -*-
main([BeamFile]) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(BeamFile,[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
View a.ex
defmodule A do
use Mockery
@b Mockery.of(B)
@c C
@d Mockery.of("D")
def run do
@b.fun()
@c.fun()
@teamon
teamon / box.ex
Created Aug 25, 2017
Define elixir structs with typespec with single line of code
View box.ex
defmodule Box do
defmacro __using__(_env) do
quote do
import Box
end
end
@doc """
Define module with struct and typespec, in single line
View js_exception_catcher.ex
defmodule Appsignal.Plug.JSExceptionCatcher do
@behaviour Plug
import Plug.Conn
alias Appsignal.Transaction
@defaults [
path: "/appsignal_error_catcher",
namespace: :frontend
]
View twin.ex
defmodule Twin do
@moduledoc """
See http://teamon.eu/2017/different-approach-to-elixir-mocks-doubles/
Example usage
defmodule MyApp.Main do
@api Twin.get(MyApp.Api)
def run do
You can’t perform that action at this time.