Skip to content

Instantly share code, notes, and snippets.

khia

Block or report user

Report or block khia

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
View gist:3874237
iex(6)> defmodule Test do
...(6)> defmacrop foo() do
...(6)> quote location: [line: 54], do: __ENV__.line
...(6)> end
...(6)> def test, do: foo
...(6)> end
iex:6: redefining module Test
{:module,Test,<<70,79,82,49,0,0,5,52,66,69,65,77,65,116,111,109,0,0,0,146,0,0,0,16,11,69,108,105,120,105,114,45,84,101,115,116,8,95,95,105,110,102,111,95,95,4,100,111,99,115,...>>,{:test,0}}
iex(7)> Test.test
10
View gist:3900083
```
Performance:
| asymptotic | length |
| | 10 | 100 | 1000 | 10000 |
| |min med max avg|min med max avg|min med max avg|min med max avg|
cons | | 0, 0, 537, 0 | 0, 0, 572, 0 | 0, 0, 223, 0 | 0, 0, 431, 0 |
drop | | 0, 0, 204, 0 | 0, 1, 356, 1 | 1, 1, 204, 1 | 1, 1, 450, 2 |
drop_tail | | 2, 3, 393, 3 | 1, 2, 588, 2 |294,302,501,306|2627,2768,9390,2812|
drop_tail_r| | 1, 2, 588, 2 | 16,17,404,17 |156,165,385,167|1364,1486,3650,1498|
from_list_r| | 0, 1, 405, 1 | 9,10,519,10 |112,114,879,116| 996,1037,3104,1060|
View gist:3960612
defmacrop _pid(args) do
[_self|rest] = Enum.reverse(args)
session_pid = quote do: unquote(_self).session_pid
element = quote do: unquote(_self).element
[session_pid,element|Enum.reverse(rest)]
end
delegate [element(strategy, value, _self)],
to: :htse_session, as: :element_element, with: _pid
View gist:3960633
delegate [
capabilities(_self),
delete(_self),
url(_self), url(url, _self),
forward(_self), back(_self),
],
to: :htse_session, with: _pid
View gist:4312157
'/Users/some_user/dev/myproject/apps/myapp/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/gen_leader/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/edown/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/gproc/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/genx/ebin',
'.',
'/usr/local/dev/erlang/R15B02/lib/erlang/lib/kernel-2.15.2/ebin',
'/usr/local/dev/erlang/R15B02/lib/erlang/lib/stdlib-1.18.2/ebin',
'/Users/some_user/dev/myproject/deps/elixir/bin/../lib/mix/ebin',
'/Users/some_user/dev/myproject/deps/elixir/bin/../lib/iex/ebin',
@khia
khia / dsl.exs
Last active Dec 12, 2015
Demo of simple DSL
View dsl.exs
#!/usr/bin/env elixir
defmodule DSL do
defmacro action(match, [do: body]) do
quote do
def handle_info(unquote(match) = arg, state) do
unquote(body)
{:ok, state}
end
end
end
View gist:5398228
def project do
your_options = []
[
...
elixirc_options: your_options ++ options(Mix.env)
]
end
defp options(env) when env in [:dev, :test] do
[exlager_level: 7]
@khia
khia / README.txt
Created Nov 20, 2013
mix compile macro from different app
View README.txt
$ mix
==> common
Compiled lib/classes.ex
Generated common.app
==> macro
Compiled lib/method.ex
Generated macro.app
$ touch apps/common/lib/classes.ex
$ mix
==> common
View apps_bexng_mix.exs
cat apps/bexng/mix.exs
defmodule Bexng.Mixfile do
use Bexng.Project
def project do
[ app: :bexng,
version: "0.0.1",
elixir: ">= 0.14.3-dev",
deps: deps ]
end
View gist:606c51e2c4123f2d87ef
defmodule Test do
defstruct foo: nil, bar: nil
for x <- @keys do # <-------------------------- HOW ????
def parse(unquote(x)), do: something(x)
def parse(unquote(Atom.to_string(x))), do: something(x)
end
end
You can’t perform that action at this time.