Skip to content

Instantly share code, notes, and snippets.

defmodule SupportChat do
import Phoenix.Component
alias Phoenix.LiveView.JS
@doc """
Chat bubble at the bottom right corner.
"""
def bubble(assigns) do
~H"""
<div>
@teamon
teamon / copy_link.ex
Last active July 19, 2022 10:09
LiveView Storybook
@teamon
teamon / Dockerfile
Created August 31, 2018 10:28
elixir + phoenix + node 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
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)
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"}
@teamon
teamon / mix_xref.txt
Created October 19, 2017 08:49
tesla ref
⌘ ~/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 October 7, 2017 15:45
HTTP 1.0 web server in Erlang with persistent connections (Connection: keep-alive)
#!/usr/bin/env escript
%% Original author - Steve Vinoski <[email protected]>
%% Modifications by - Tymon Tobolski <[email protected]>
%% 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 September 21, 2017 12:07
Decomile BEAM (erlang, elixir) into erlang with syntax highlighting
#!/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))]).
@teamon
teamon / a.ex
Created September 14, 2017 10:30
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 August 25, 2017 23:09
Define elixir structs with typespec with single line of code
defmodule Box do
defmacro __using__(_env) do
quote do
import Box
end
end
@doc """
Define module with struct and typespec, in single line