Skip to content

Instantly share code, notes, and snippets.

version: "3.8"
services:
app:
image: papereira/devcontainer-elixir-phoenix:1.5.6-alpine
volumes:
- ../:/workspace
- ~/.ssh:/home/vscode/.ssh:ro
- ~/.ssh:/root/.ssh:ro
- /var/run/docker.sock:/var/run/docker.sock
# pubsub request
http://localhost:4567/api/v1/pubsub/twitter
json: {"search":"myelixirstatus", "number": 20}
# response
{
uuid: "1bab11d8-f4f9-45c3-ace5-cffc907135b2"
search_string: "myelixirstatus"
number_of_tweets: 20
requested_at: "2015-11-18 17:48:22 +0000"
Rails as it has never been before :)
Rails 3 AntiPatterns, Useful snippets and Recommended Refactoring. Note: Some of them are collected from different online resources/posts/blogs with some tweaks.
@pap
pap / connection_table.ex
Created August 11, 2014 13:23
ETS table wrapper module
defmodule ConnectionTable do
@table_id __MODULE__
def init do
:ets.new(@table_id, [:public, :named_table])
end
def insert(key, value) do
:ets.insert(@table_id, {key, value})
@pap
pap / phoenix compilation error
Created June 13, 2014 15:17
Phoenix compilation error
* Getting cowboy (git://github.com/extend/cowboy.git)
Cloning into '/Users/paulopereira/Devel/TheLab/00.Research/pknoa/dev/pknoa_phoenix/deps/cowboy'...
remote: Reusing existing pack: 6124, done.
remote: Total 6124 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6124/6124), 3.68 MiB | 560.00 KiB/s, done.
Resolving deltas: 100% (3602/3602), done.
Checking connectivity... done.
* Getting cowlib (git://github.com/extend/cowlib.git)
Cloning into '/Users/paulopereira/Devel/TheLab/00.Research/pknoa/dev/pknoa_phoenix/deps/cowlib'...
remote: Reusing existing pack: 185, done.
@pap
pap / elixir_katas.exs
Created April 24, 2014 14:12
Codewars perfect square ruby kata implemented in elixir
# The ruby kata was:
# Given an array of numbers, which are perfect squares?
# get_squares(1..16) # => [1, 4, 9, 16]
# get_squares(1..100) # => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
#
# This version accepts lists an ranges
defmodule ElixirKatas do
def get_squares(numbers) do
@pap
pap / over_the_head.ex
Last active August 29, 2015 13:56
Having fun with the pipe operator ! I wouldn't use this without making the code boring. But while i don't i'm having fun
defmodule TestApp.Utils do
@doc """
Returns `true`if `:app` is running; otherwise returns `false`
"""
@spec is_app_running?(atom) :: boolean
def is_app_running?(appname) do
(:application.which_applications |>
Enum.filter(fn(x)->Enum.member? tuple_to_list(x), appname end) |>
Enum.count) > 0
=ERROR REPORT==== 14-Oct-2013::20:24:51 ===
Error in process <0.370.0> with exit value: {[{reason,{'Elixir.CompileError','__exception__',<<6 bytes>>,8,<<26 bytes>>}},{mfa,{'Elixir.Handler.WeberReqHandler',handle,2}},{stacktrace,[{elixir_translator,translate_arg,2,[{file,"src/elixir_translator.erl"},{line,573}]},{lists,mapfoldl,3,[{file...
=ERROR REPORT==== 14-Oct-2013::20:24:51 ===
Ranch listener http had connection process <0.370.0> exit with reason: {[{reason,{'Elixir.CompileError','__exception__',<<"nofile">>,8,<<"function style/1 undefined">>}},{mfa,{'Elixir.Handler.WeberReqHandler',handle,2}},{stacktrace,[{elixir_translator,translate_arg,2,[{file,"src/elixir_translator.erl"},{line,573}]},{lists,mapfoldl,3,[{file,"lists.erl"},{line,1339}]},{elixir_translator,translate_args,2,[{file,"src/elixir_translator.erl"},{line,580}]},{elixir_translator,translate_apply,7,[{file,"src/elixir_translator.erl"},{line,609}]},{elixir_compiler,'__FILE__',2,[{file,<<"nofile">>},{line,1}]},{elixir_compiler,'__FILE__',2,[{fi