This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule KV.GenServer do | |
| use GenServer | |
| def start_link(opts), do: GenServer.start_link(__MODULE__, :ok, opts) | |
| def lookup(server, name), do: GenServer.call(server, {:lookup, name}) | |
| def create(server, name, value), do: GenServer.cast(server, {:create, name, value}) | |
| def init(:ok), do: {:ok, %{}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Ecto.Model.SQL.Init do | |
| def gen_sql_create(model, strict \\ false) when is_atom(model) do | |
| table_name = model.__schema__(:source) | |
| field_names = model.__schema__(:field_names) | |
| assocs = model.__schema__(:associations) |> Enum.flat_map(fn(association) -> | |
| case model.__schema__(:association, association) do | |
| %Ecto.Reflections.BelongsTo{key: field, associated: assoc_model, assoc_key: assoc_key} -> | |
| [{field, {assoc_model.__schema__(:source), assoc_key}}] | |
| _ -> | |
| [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <<653545453567:(lists:foldl(fun erlang:'+'/2, 0, [4, 4, 8]))/little>>. | |
| => works | |
| <<653545453567 :: (:lists.foldl(&(&1 + &2), 0, [4, 4, 8]))-little>> | |
| ** (CompileError) | |
| <<653545453567 :: size(:lists.foldl(&(&1 + &2), 0, [4, 4, 8]))-little>> | |
| ** (CompileError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # github.com/liveforeverx/elixir branch: r17maps | |
| defmodule Maps do | |
| lc a inlist [:a, :b, :c] do | |
| def test(%[ unquote(a) := n ]), do: n # Use at compiletime | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule TestRegex do | |
| def erlang_regex do | |
| :re.run("abc", "([a-z]+)", [{:capture, :all_but_first, :list}]) | |
| end | |
| {:ok, regex} = :re.compile("([a-z]+)") | |
| escaped_regex = Macro.escape(regex) | |
| def compiled_regex do | |
| :re.run("abc", unquote(escaped_regex), [{:capture, :all_but_first, :list}]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Generic.BossDB.Model do | |
| defmacro defmodel(name, fields, options, do_block // []) do | |
| attributes = lc {key, _} inlist fields, do: key | |
| private = Keyword.get(options, :private, []) | |
| public_attributes = lc attr inlist attributes, not Enum.member?(private, attr), do: attr | |
| types = lc key inlist attributes, do: {key, to_char_list(key)} | |
| {atom, _, _} = name | |
| mappers = lc attr inlist attributes, do: {attr, Generic.Helper.to_bin_attr(attr)} | |
| quoted = lc {attr, bin} inlist mappers do | |
| quote do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| to_generate = | |
| [bad_request: [bad_version: 0, | |
| bad_type: 1, | |
| bad_stat: 2, | |
| bad_experimenter: 3, | |
| bad_subtype: 4, | |
| eperm: 5, | |
| bad_len: 6, | |
| buffer_empty: 7, | |
| buffer_unknown: 8], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Inspired by AngularJS' implementation of "click dblclick mousedown..." | |
| * | |
| * This ties in the Hammer events to attributes like: | |
| * | |
| * hm-tap="add_something()" | |
| * hm-swipe="remove_something()" | |
| * | |
| * and also has support for Hammer options with: | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The install script | |
| # Adapted from https://gist.github.com/579814 | |
| echo '# Added by install script for node.js and npm in 30s' >> ~/.bashrc | |
| echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc | |
| echo 'export NODE_PATH=$HOME/local/lib/node_modules' >> ~/.bashrc | |
| . ~/.bashrc | |
| mkdir -p ~/local | |
| mkdir -p ~/Downloads/node-latest-install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dynamo dima$ MIX_ENV=test mix do deps.get, test | |
| * Getting hackney [git: "https://github.com/benoitc/hackney.git"] | |
| Cloning into 'deps/hackney'... | |
| remote: Counting objects: 577, done. | |
| Receiving objects: 100% (577/577), 284.67 KiB | 187 KiB/s, done. 0% (1/577) | |
| Resolving deltas: 100% (407/407), done. | |
| * Getting edown [git: "https://github.com/esl/edown.git"] | |
| Cloning into 'deps/edown'... | |
| remote: Counting objects: 742, done. | |
| Receiving objects: 100% (742/742), 368.70 KiB | 286 KiB/s, done. |
NewerOlder