Skip to content

Instantly share code, notes, and snippets.

@dhalai
dhalai / task1.exs
Created February 13, 2017 10:00 — forked from moklett/task1.exs
Elixir Task - Crash Handling
# This demonstrates that, when using async/await, a crash in the task will crash the caller
defmodule Tasker do
def good(message) do
IO.puts message
end
def bad(message) do
IO.puts message
raise "I'm BAD!"
end
@dhalai
dhalai / inversion.exs
Last active December 14, 2016 08:14
Algorithm optimization to avoid O(n^2). Fixed version of https://medium.com/@sashang/no-debugging-programming-in-elixir-e26f3d3fd243
defmodule Inversion do
def run(filename) do
{sorted, count} = File.read!(filename)
|> String.split("\r\n", trim: true)
|> Enum.map(fn(x) -> String.to_integer(x) end)
|> devide_and_conquer
count
end
defp devide_and_conquer(data) do
defmodule Inversion do
def run(filename) do
{sorted, count} = File.read!(filename)
|> String.split("\r\n", trim: true)
|> Enum.map(fn(x) -> String.to_integer(x) end)
|> devide_and_conquer
count
end
defp devide_and_conquer(data) do
class SomeModel < ActiveRecord::Base
include Notify
tracked :on => {
:update => [{'publish', proc { |model| model.published? } },
}
end
class SomeSubscriber
include Notify