Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
@josevalim
josevalim / mix app.tree
Last active July 20, 2018 15:48
Sample output of the new "mix app.tree" and "mix deps.tree" tasks in a Phoenix project (using master). The first command shows the applications you will effectively need at runtime in production while "deps.tree" is your whole dependency tree, including compile time, dev and test dependencies.
$ mix app.tree
demo
├── elixir
├── phoenix
│ ├── elixir
│ ├── plug
│ │ ├── elixir
│ │ ├── crypto
│ │ └── logger
│ │ └── elixir
@josevalim
josevalim / authorize.ex
Last active April 29, 2018 09:16 — forked from jeremytregunna/authorize.ex
This looks horrible (formatter)
defmodule Api.Authorize do
alias Account.Models.User
def board?(board_id, %User{} = user, available_permissions, required_permissions) do
with(
{:ok, board} <- Tracker.Board.find(board_id),
true <- Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id),
^required_permissions <-
Enum.to_list(
MapSet.intersection(
@josevalim
josevalim / keybase.md
Last active January 24, 2017 23:24
keybase.md

Keybase proof

I hereby claim:

  • I am josevalim on github.
  • I am josevalim (https://keybase.io/josevalim) on keybase.
  • I have a public key whose fingerprint is E140 099F 114F 4B2A 21FE 2E69 E337 0FF7 D467 E599

To claim this, I am signing this object:

$ git clone git@github.com:elixircnx/comeonin.git
$ cd comeonin/
$ git checkout develop
$ mix deps.get
$ mix test
defmodule Interleave do
def interleave(a, b) do
af = Seq.impl_for(a)
bf = Seq.impl_for(b)
do_interleave_1(af, a, bf, b, []) |> :lists.reverse()
end
defp do_interleave_1(af, a, bf, b, acc) do
case af.next(a) do
{ :next, i, a } ->
% from my unit tests
foo = 10
assert 10 == my_macro(:foo)
assert 10 == my_macro("foo")
% macro
defmacro my_macro(some_var) when is_atom(some_var) do
defmodule Dict.Behaviour do
# It is assumed that the client module implements following functions:
#
# size/1, fetch/2, put/3, reduce/3, update/4, delete/2
#
defmacro __using__(_) do
quote do
# Following are exact copies of HashDict:
def get(dict, key, default // nil) do
defmodule ExCoder do
vars = [ { "&Tab;", " " },
{ "&excl;", "!" },
{ "&quot; &QUOT;", "\"" },
{ "&num;", "#" },
{ "&dollar;", "$" },
{ "&percnt;", "%" },
{ "&amp; &AMP;", "&" },
{ "&apos;", "'" },
{ "&lpar;", "(" },
Warden::Manager.after_authentication do |record, warden, options|
warden.request.session.try(:delete, :_csrf_token)
end
@josevalim
josevalim / def.exs
Last active December 20, 2015 08:19 — forked from avdi/def.exs
def next_state do
(board, x, y) ->
cell = cell_at(board, x, y)
live_count = live_neighbors(board, x, y)
next_state(cell, live_count)
(_, x, y) when (x < 0 or y < 0) ->
"."
end
def next_state do