elixir

Idiom to construct a URI with a query string in Elixir

风流意气都作罢 提交于 2021-02-20 09:59:13
问题 I'm wondering what the most idiomatic way is to use URI to add a query string to a base URI in Elixir. I'm currently doing something like this: iex(1)> base = "http://example.com/endpoint" "http://example.com/endpoint" iex(2)> query_string = URI.encode_query(foo: "bar") "foo=bar" iex(3)> uri_string = URI.parse(base) |> Map.put(:query, query_string) |> URI.to_string "http://example.com/endpoint?foo=bar" But was wondering if there is a cleaner way to set the query string. I know about URI.merge

UTF8, codepoints, and their representation in Erlang and Elixir

时光毁灭记忆、已成空白 提交于 2021-02-18 19:13:07
问题 going through Elixir's handling of unicode: iex> String.codepoints("abc§") ["a", "b", "c", "§"] very good, and byte_size/2 of this is not 4 but 5, because the last char is taking 2 bytes, I get that. The ? operator (or is it a macro? can't find the answer) tells me that iex(69)> ?§ 167 Great; so then I look into the UTF-8 encoding table, and see value c2 a7 as hex encoding for the char. That means the two bytes (as witnessed by byte_size/1) are c2 (94 in decimal) and a7 (167 in decimal). That

Mixed Erlang/Elixir projects - can I use mix or rebar?

谁都会走 提交于 2021-02-18 06:03:02
问题 For Erlang code, I use rebar . For Elixir code, I use the built-in mix tool. Now I want to have a mixed Erlang/Elixir project. Can I use rebar to compile Elixir code? Or can I use mix to compile Erlang code? If so, how? 回答1: Mix can compile erlang files if you put them in src . There is a rebar_elixir_plugin to compile Elixir code from rebar but it is not as efficient at it as Mix. 来源: https://stackoverflow.com/questions/19776403/mixed-erlang-elixir-projects-can-i-use-mix-or-rebar

Mixed Erlang/Elixir projects - can I use mix or rebar?

此生再无相见时 提交于 2021-02-18 06:02:46
问题 For Erlang code, I use rebar . For Elixir code, I use the built-in mix tool. Now I want to have a mixed Erlang/Elixir project. Can I use rebar to compile Elixir code? Or can I use mix to compile Erlang code? If so, how? 回答1: Mix can compile erlang files if you put them in src . There is a rebar_elixir_plugin to compile Elixir code from rebar but it is not as efficient at it as Mix. 来源: https://stackoverflow.com/questions/19776403/mixed-erlang-elixir-projects-can-i-use-mix-or-rebar

how to make request per second without waiting for previous one to complete in GenServer Elixir

房东的猫 提交于 2021-02-11 12:23:25
问题 GenServer with 1 HTTP request per second This is related to the above question, So I have posted the link. I have made such GenServer worker. this my whole GenServer defmodule Recording.Worker do use GenServer require Logger def start_link(opts) do {id, opts} = Map.pop!(opts, :id) GenServer.start_link(__MODULE__, opts, name: id) end def init(state) do schedule_fetch_call(state.sleep) {:ok, state} end def handle_info(:jpeg_fetch, state) do {for_jpeg_bank, running} = make_jpeg_request(state

How can I get reliable jump-to-definition for Elixir?

折月煮酒 提交于 2021-02-10 16:14:05
问题 I tried the Elixir plugin for Jet Brains, and two of them for VS Code, but so far none of them reliably takes me to the definition of functions and modules. Apparently part of the reason is because elixir-lsp cannot handle things inside of scope blocks (https://github.com/elixir-lsp/elixir-ls#known-issueslimitations). 回答1: I have a stop-gap solution for this using Universal Ctags. On Mac: brew install --HEAD universal-ctags/universal-ctags/universal-ctags /usr/local/bin/ctags --exclude=node

Hacker News 简讯 2021-02-10

牧云@^-^@ 提交于 2021-02-10 05:55:11
最后更新时间: 2021-02-10 05:00 Creeping as a Service - (every.to) - [中文翻译版] 作为服务爬行 得分:90 | 评论:11 | 评论翻译 Browser Fuzzing at Mozilla - (hacks.mozilla.org) - [中文翻译版] Mozilla浏览器模糊化 得分:111 | 评论:6 | 评论翻译 Minesweeper automates root cause analysis as a first-line defense against bugs - (fb.com) - [中文翻译版] 扫雷艇自动进行根本原因分析,作为对付虫子的第一道防线 得分:45 | 评论:7 | 评论翻译 Launch HN: SigNoz (YC W21) – Open-source alternative to DataDog - [中文翻译版] 发布HN:SigNoz(ycw21)–DataDog的开源替代品 得分:146 | 评论:47 | 评论翻译 Pattern Matching Accepted for Python - (lwn.net) - [中文翻译版] Python接受的模式匹配 得分:72 | 评论:29 | 评论翻译 Looking at GSM security 30 years later

How do interpolation fields in Ecto queries?

不问归期 提交于 2021-02-08 11:14:52
问题 The Ecto documentation shows how to do interpolation values. But I need dynamic fields in my queries. I have dozens of fields and write queries for each of them does not seem cohesive. defmodule Hedone.SearchController do use Hedone.Web, :controller alias Hedone.User def idade(conn, %{"idade+" => maior, "idade-" => menor, "campo" => campo}) do IO.inspect campo query = from u in User, where: u.campo > ^maior and u.campo < ^menor, select: u.name pesquisa = Repo.all query IO.inspect pesquisa

What is the exact meaning of the equal sign in Elixir?

Deadly 提交于 2021-02-05 06:18:46
问题 I don't get what exactly means the equal sign in Elixir. What is unclear is that it looks like a mix between assignment and a pattern matching operation. iex(1)> x=4 4 iex(2)> y=5 5 iex(3)> 3=y ** (MatchError) no match of right hand side value: 5 iex(3)> y=3 3 iex(4)> y=x 4 I understand that in Elixir, the equals operator means to match the left side of the = sign to the the right side. First two lines make sense to me. x and y are unbound variables, hence they could match anything. They are

In Elixir, Phoenix, how to get session in other module as a module use Phoenix.Channel?

只谈情不闲聊 提交于 2021-02-04 18:39:25
问题 In Elixir and Phoenix, I can get session in Controller by Plug.Conn.get_session(conn, :id) So how to get session in other module as a module use Phoenix.Channel ? 回答1: Plug.Conn is not available in Phoenix.Channel. Channels rely on Phoenix.Socket instead and you can use Phoenix.Token for authentication. Here's a tutorial on how to authenticate channels in Phoenix. 来源: https://stackoverflow.com/questions/34446712/in-elixir-phoenix-how-to-get-session-in-other-module-as-a-module-use-phoenix-c