Skip to content

Instantly share code, notes, and snippets.

View TattdCodeMonkey's full-sized avatar

Rodney Norris TattdCodeMonkey

View GitHub Profile
@TattdCodeMonkey
TattdCodeMonkey / flow.exs
Created October 19, 2016 15:00
NashElixir - 10/18/2016 - Hacking with Flow v0.7
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))
@TattdCodeMonkey
TattdCodeMonkey / test.ex
Last active August 24, 2016 01:13
NashFP 8/23/2016
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}) ->
defmodule TcpUsage do
use GenServer
defmodule State do
defstruct socket: nil
end
def start_link, do: GenServer.start_link(__MODULE__, [])
def init(_) do
defmodule Nothing do
defstruct([])
@type t :: %__MODULE__{}
end
defmodule Name do
defstruct first: "", last: ""
@type t :: %__MODULE__{first: String.t, last: String.t}
@TattdCodeMonkey
TattdCodeMonkey / gproc_pubsub.ex
Last active February 19, 2016 11:51
simple elixir gproc pub/sub example for blog post
# supervisor.ex
defmodule EventSup do
use Supervisor
def start_link, do: Supervisor.start_link(__MODULE__, [], [])
def init(_) do
supervise(
[
worker(EventHandler, [:event_manager])
@TattdCodeMonkey
TattdCodeMonkey / genevent_example.ex
Last active February 19, 2016 11:52
Trivial mostly representative example of GenEvent usage for blog post
# 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]),
@TattdCodeMonkey
TattdCodeMonkey / gist:7ff07258c6f9da7e4456
Last active September 29, 2015 02:59
Elixir v1.1.0 crash report
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>},
@TattdCodeMonkey
TattdCodeMonkey / gist:e08acb86343bc8e43866
Created July 25, 2015 02:26
Justin Weiss - Is Rails fast enough?
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?
def my_function(value) when is_atom(value) do
IO.puts "atom"
end
@TattdCodeMonkey
TattdCodeMonkey / gist:f63c04ea93a73f6efab4
Created February 2, 2015 00:21
Config map update issue
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 """