This file contains 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
// akka-actor cheatsheet | |
// extract from http://doc.akka.io/actors-scala | |
class MyActor extends Actor { // Logging is included in Actor | |
// messages | |
def receive = { | |
case "foo" => | |
doBar | |
case "logging" => |
This file contains 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
@doc """ | |
Validate each array element with validator | |
Examples | |
iex> changeset | |
...> |> validate_each(:emails, &validate_email) | |
...> |> validate_each(:phones, &validate_format(&1, &2, ~r/\d+/)) | |
...> |> validate_each(:phones, &validate_length/3, is: 4) | |
""" | |
def validate_each(changeset, field, validator, opts) do |
This file contains 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
# gem "ruby-prof" | |
around_filter :profiler | |
def profiler(&block) | |
data = RubyProf::Profile.profile(&block) | |
filepath = Rails.root.join("tmp", "profiler.html") | |
File.open(filepath, "w") do |f| | |
RubyProf::CallStackPrinter.new(data).print(f) |
This file contains 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
1. Download and install d2xx drivers http://www.ftdichip.com/Drivers/D2XX/MacOSX/D2XX1.0.4.dmg (from http://www.ftdichip.com/Drivers/D2XX.htm) | |
2. Install OpenOCD from homebrew (http://mxcl.github.com/homebrew/) | |
$ brew install openocd --enable-ft2232_libftdi |
This file contains 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
// POST http://staginginfo.marketmaker4.com/api/v1/projects.json | |
{ | |
"project": { | |
"actor_uid": "7ajxdiGvTvZ8DJoT2uY4", | |
"list": { | |
"name": "Test 1329343404", | |
"companies": [ | |
{ | |
"contact_person": { | |
"email": "dellis@monachem.mc", |
This file contains 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
# Much simplified version based on https://github.com/zhangsoledad/alchemic_avatar | |
# Avatar.generate/2 returns a Plug.Upload that can be passed directly | |
# into Ecto.Changeset (as for example fallback image) | |
defmodule Avatar do | |
@defaults [ | |
size: 300, | |
font_path: Application.app_dir(:my_app, "priv/fonts/Roboto.ttf"), | |
font_size: 40, | |
font_weight: 500, |
This file contains 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 Twin do | |
@moduledoc """ | |
See http://teamon.eu/2017/different-approach-to-elixir-mocks-doubles/ | |
""" | |
## PROXY | |
defmodule Proxy do | |
def unquote(:"$handle_undefined_function")(fun, args) do | |
[{__MODULE__, mod} | rest] = Enum.reverse(args) |
This file contains 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 Test do | |
def run(x) do | |
with :error <- try_one(x), | |
:error <- try_two(x), | |
:error <- try_three(x) do | |
:error | |
end | |
end | |
defp try_one(1), do: {:ok, "one"} |
This file contains 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
⌘ ~/code/tesla (master) λ mix xref graph | |
lib/tesla.ex | |
├── lib/tesla/adapter/hackney.ex (compile) | |
│ ├── lib/tesla/multipart.ex (compile) | |
│ └── lib/tesla.ex | |
├── lib/tesla/adapter/httpc.ex (compile) | |
│ ├── lib/tesla/adapter/shared.ex (compile) | |
│ ├── lib/tesla/multipart.ex (compile) | |
│ └── lib/tesla.ex | |
├── lib/tesla/adapter/ibrowse.ex (compile) |
This file contains 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 Sync.Middleware.RateLimit do | |
@defaults [ | |
delay: 2000, | |
max_retries: 5 | |
] | |
def call(env, next, opts) do | |
opts = opts || [] | |
delay = Keyword.get(opts, :delay, @defaults[:delay]) | |
max_retries = Keyword.get(opts, :max_retries, @defaults[:max_retries]) |