DRYな備忘録

Don't Repeat Yourself.

elixir

【Elixir】argument error, :erlang.++({'content-type', 'image/png'}, [])

いやーよくわからないエラーメッセージとスタックトレースなんだけど。なんか深そうだし。 ** (exit) an exception was raised: ** (ArgumentError) argument error :erlang.++({'content-type', 'image/png'}, []) (erlcloud) src/erlcloud_s3.erl:699: :er…

【Elixir】protocol String.Chars not implemented for【エラー】

っていうエラーが出る protocol String.Chars not implemented for %{"avatar_url" => "https://avatars.githubusercontent.com/u/12345?v=3"} 文字列補完(string interpolation)に、String.Charsを持っていないデータ(MapとかStruct)を渡していることに…

【Elixir】Ecto.Migrationで外部キー参照とNOT NULL制約を追加

こういうことを学んだので↓ otiai10.hatenablog.com これを、Ecto.Migrationでやりたい defmodule MyApp.Repo.Migrations.CreateUserToken do use Ecto.Migration def change do create table(:posts) do add :user_id, references(:users, on_delete: :dele…

【Elixir】Module内のfunctionのリストを取得する

stackoverflow.com Ecto.Repo.__info__(:functions) [__adapter__: 0, __pool__: 0, __query_cache__: 0, __repo__: 0, all: 1, all: 2, config: 0, delete: 1, delete: 2, delete!: 1, delete!: 2, delete_all: 1, delete_all: 2, get: 2, get: 3, get!: 2,…

Ecto.Migration内でINSERTする

Ecto.Migration – Ecto v2.0.0-beta.0 execute使お... defmodule MyApp.Repo.Migrations.CreateProviderTable do use Ecto.Migration def change do create table(:providers) do add :name, :string timestamps end create unique_index(:providers, [:name…

Elixirで無名関数の実行

Elixir (iex) iex(1)> (fn msg -> IO.puts msg end).("hello!") hello! :ok Go func(msg string) { fmt.Println(msg) }("hello!")

ElixirでFizzBuzz

前回まで 【Elixir】バージョン管理しつつErlangとElixirをMacにインストールする - DRYな備忘録 【Elixir】the result of the expression is ignored - DRYな備忘録 【Elixir】use of operator === has no effect と言われる - DRYな備忘録 Elixirでゼロ埋…

Elixirでゼロ埋め【zero padding】【elixir】

iex(6)> String.rjust("hoge", 8, ?0) "0000hoge" zero paddingしたい対象がintegerなら、適宜、第1Integer.to_striingなど使う。 123 |> Integer.to_string |> String.rjust(8, ?0) 参考 In Elixir, how do you format numbers with string interpolation -…

【Elixir】use of operator === has no effect と言われる

問題 Elixirのコンパイラに掲題のように叱られる。 原因 「===使ってもええんやで」という意味。 解決 1..max |> Enum.each fn(n) -> - case {rem(n, 3) == 0, rem(n, 5) == 0} do + case {rem(n, 3) === 0, rem(n, 5) === 0} do {true, true} -> 雑感 たと…

【Elixir】the result of the expression is ignored

問題 ElixirでFizzBuzz書いてて、掲題のように怒られる main.exs:4: warning: the result of the expression is ignored (suppress the warning by assigning the expression to the _ variable) the result of the expression is ignored (suppress the war…

【Elixir】バージョン管理しつつErlangとElixirをMacにインストールする

just want "Hello, World"? brew install elixirで、ErlangもElixirも入ります。 参考 qiita.com Prerequisite JDK installed on your mac brew install wget Good Bye Elixir, installed via brew brewで入れたelixirは消す % brew uninstall elixir % brew…