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
| dir_of_wiki = "Archive" | |
| file_name = "fixtures/war_and_peace.txt" | |
| alias Experimental.Flow | |
| defmodule OurTest do | |
| def count_words_single(file_name) do | |
| File.stream!(file_name) | |
| |> Enum.flat_map(&String.split(&1,~r(\b), trim: true)) |
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
| Agent.start_link(&HashDict.new/0, name: :wikipedia) | |
| file_results = [] | |
| Enum.each(file_results, fn ({file, words}) -> | |
| Enum.each(words, fn word -> | |
| Agent.update( | |
| :wikipedia, | |
| fn dict -> | |
| Dict.update(dict, word, {file, 1}, fn ({file, cnt}) -> |
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 TcpUsage do | |
| use GenServer | |
| defmodule State do | |
| defstruct socket: nil | |
| end | |
| def start_link, do: GenServer.start_link(__MODULE__, []) | |
| def init(_) 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
| defmodule Nothing do | |
| defstruct([]) | |
| @type t :: %__MODULE__{} | |
| end | |
| defmodule Name do | |
| defstruct first: "", last: "" | |
| @type t :: %__MODULE__{first: String.t, last: String.t} |
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
| # supervisor.ex | |
| defmodule EventSup do | |
| use Supervisor | |
| def start_link, do: Supervisor.start_link(__MODULE__, [], []) | |
| def init(_) do | |
| supervise( | |
| [ | |
| worker(EventHandler, [:event_manager]) |
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
| # supervisor.ex | |
| defmodule EventSup do | |
| use Supervisor | |
| def start_link, do: Supervisor.start_link(__MODULE__, [], []) | |
| def init(_) do | |
| supervise( | |
| [ | |
| worker(GenEvent, [[name: :event_manager]], [id: :event_manager]), |
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
| On OSX 10.9.5. elixir and erlang installed from brew. I see the following when running `iex`, `mix`, `elixir` etc. | |
| =ERROR REPORT==== 28-Sep-2015::21:53:12 === | |
| ** gen_event handler 'Elixir.Logger.ErrorHandler' crashed. | |
| ** Was installed in error_logger | |
| ** Last event was: {info_report,<0.38.0>, | |
| {<0.40.0>,progress, | |
| [{supervisor,{local,'Elixir.Logger.Supervisor'}}, | |
| {started, | |
| [{pid,<0.45.0>}, |
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
| Is Rails fast enough? | |
| When a new language or web framework pops up, what do you usually see along with it? | |
| Benchmarks. Benchmarks like these. | |
| As a Rails developer, you might be embarassed to see this. I mean, Rails is more than a full order of magnitude slower than Phoenix! And even Sinatra is about 3x faster. | |
| But what do you do about stats like this? Do you shift to another language, so you can get faster response times? Do you move to a different architecture, with some services written in Go, some in Elixir, talking to a frontend in JavaScript? What would you even use Rails for, then? |
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
| def my_function(value) when is_atom(value) do | |
| IO.puts "atom" | |
| 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 HMC5883L.Configuration do | |
| defstruct averaging: 8, data_rate: 15, bias: :normal, gain: 1.3, scale: 0.0, mode: :continuous, i2c_channel: "i2c-1", i2c_devid: 0x1E | |
| alias __MODULE__ | |
| alias HMC5883L.Utilities | |
| @type t :: %Configuration{averaging: number, data_rate: number, bias: atom, gain: number, scale: number, mode: atom, i2c_channel: String.t, i2c_devid: byte} | |
| import MultiDef | |
| def new(), do: %Configuration{} | |
| @doc """ |
NewerOlder