Questions tagged [elixir]

Elixir is an open-source, dynamic, compiled, general purpose functional programming language. It was designed to be fully compatible with the Erlang platform and is well suited to writing fault-tolerant, distributed applications with soft real-time guarantees and the ability for hot-code-swapping.

Filter by
Sorted by
Tagged with
0
votes
2answers
28 views

Nested function defenitions

i'm just working through Programming Elixir and imlpementing Split. My code as is follows - defmodule MyEnum do def split(l, n) do def split_helper([], pre, _n), do: {pre, []} ...
0
votes
1answer
16 views

Simple Elixir / Plug Processes Issue - PID not sticking around

I'm just starting out in Elixir and wanted to build a very simple API with Plug. I used this guide to get a very simple API up and running. Basically, the problem I'm facing is that the process that ...
-1
votes
0answers
25 views

Elixir System.cmd “git”, [“shortlog”] doesn't ever return, why? [duplicate]

I'm trying to get the git shortlog -s summary list from within Elixir. But using System.cmd it never returns. Ugh. Other git commands work just fine: System.cmd "git", ["log"] has no problem. iex(...
-2
votes
4answers
62 views

Insert item in list after two elements

I have the list [%{A: %{}}, %{B: %{}}, %{C: %{}}] how could I add %{D: %{}} between B and C based not in the index, like this: [%{A: %{}}, %{B: %{}}, %{D: %{}}, %{C: %{}}]
1
vote
2answers
29 views

How to update Elixir struct with key in variable

I have some struct definition defmodule Foo do defstruct [:a, :b] end And I have some struct a = %Foo{a: 1, b: 2} I'm able to get new struct using pipe (like map) %Foo{a | b: 3} %Foo{a: 1, b: 3}...
0
votes
0answers
34 views

des-ecb Encryption in elixir/erlang

How do i pass a 24 byte key to elixir/erlang block_encrypt des-ecb cipher. As a follow up to my previous question How to set a 24 byte length key to elixir/erlang block_encrypt/4 function using ...
0
votes
0answers
35 views

How do i fix the installation mistake or error

I tried to install elixir following the installation guide from their official docs. after the 1st step it asked me a code something squeeze was written in it i changed that to my name i thought i ...
-2
votes
0answers
27 views

“'$' by itself is not a valid FieldPath” [on hold]

Using mongodb with elixir in my code and getting an error with message "'$' by itself is not a valid FieldPath". I am not sure what the error is or the fix.
1
vote
1answer
47 views

In Elixir with Postgres, how can I have the database return the enum values which are NOT in use?

I have an EctoEnum.Postgres: # @see: https://en.wikipedia.org/wiki/ISO_4217 defmodule PricingEngine.Pricing.CurrencyEnum do @options [ :AED, :AFN, # snip... :ZWL ] use EctoEnum....
1
vote
1answer
19 views

File.rm! can't delete File.mkdir created directory

Simply trying to delete a directory. Can't because of not owner error. iex(1)> File.mkdir "testing" :ok iex(2)> File.rm! "testing" ** (File.Error) could not remove file "testing": not owner ...
3
votes
1answer
45 views

Why doesn't phx.new create my elixir project with the latest elixir version?

I use the asdf package manager and when I run the command asdf current elixir, it returns 1.9.1 (set by /Users/my_user/.tool-versions). I created a project with the command mix phx.new my_project -...
1
vote
0answers
29 views

Elixir - plug is being triggered in other actions in Phoenix controller

I'm using PolicyWonk for authorization and I created this policy: def policy( %{current_user: current_user, organisation: organisation} = _assigns, :organisation_view ) when not is_nil(...
1
vote
1answer
37 views

Redirect after POST using plug_cowboy (2.0)

I got a simple Plug post handler like this post "/some/url" do # do something # render(something) end …but I would like to redirect somehow to another get handler, instead of rendering html. ...
0
votes
2answers
53 views

How to join and filter between 3 tables with ecto query expressions?

I have 3 schemas: Post, Author, Assistant. Post belongs_to :author Author has_many :posts and has_one :assistant Assistant belongs_to :author I want to build a query that only gets Posts where the ...
0
votes
3answers
49 views

Why doesn't Enum.filter work with a dictionary parameter?

I'm filtering a list using Enum.filter/2. I've simplified the code to it's bare essentials to isolate what's happening, but I can't understand where it's going wrong. Here's the code: defmodule ...
3
votes
4answers
86 views

Check if all elements in list have a :ok element

I have one list of tuples like this [ {:ok, {"0000 0000 "}}, {:ok, %{AM01: %{"C4" => "1111", "C5" => "1"}}}, {:ok, %{AM04: %{"C2" => "2222", "C6" => "2"}}} ] The first ...
3
votes
4answers
85 views

Binary pattern matching - Can I extract the numbers out of “/word/number/word/number”

I know how to do this with regular String operations, but I'm curious if it's possible to match in one step. Let's say I have accounts/123123/order/234234234. It's from an external source, so while I ...
2
votes
0answers
47 views

Handling Exceptions in Absinthe

The Issue There are a lot of guides available for handling error tuples in absinthe but next to zero for exceptions. This is important because there are always unforseen issues which might raise an ...
0
votes
1answer
47 views

Error (failed_to_start_child) when running ecto in ejabberd production mode inside docker

I added ecto to ejabberd, which worked fine in dev mode (run with iex -S mix), but when ejabberd is compiled and started I get this error: 07:02:09.214 [error] Failed to start module <module-name&...
0
votes
2answers
49 views

How test controller authorization

I have a controller similar to this simplified code: defmodule Web.UserController do use Web, :controller alias App.User action_fallback Web.FallbackController def authorize(conn) do # ...
0
votes
1answer
80 views

Serve Static Images with Phoenix Elixir

I am trying to deploy an API with Heroku, using Elixir and Phoenix. In some use cases, I need to send an HTML email (that is all figured out and sending properly), however, images used on the email ...
0
votes
1answer
37 views

How to set a 24 byte length key to elixir/erlang block_encrypt/4 function using des_ede3 as mode of encryption

Am trying to send data to an external api that expects encrypted data using 3DES encryption but am having issues understanding how to pass my api key as the key field to erlangs des_ede3 cipher. ...
1
vote
3answers
63 views

Why does my Enum.reduce based implementation of Enum.all? return an empty list?

The Elixir help page for Enum.reduce/3 says that almost all of the Enum functions can be implemented on top of Enum.reduce/3. I am trying to implement Enum.all?/1 by writing a new function that uses ...
1
vote
1answer
55 views

how to supervise a method in elixir

I am trying to supervise a method in elixir. I have this module as EvercamMedia.SnapshotExtractor.CloudExtractor as GenStage and I am passing some arguments to it such as. def handle_cast({:...
5
votes
2answers
94 views

In Elixir, is there any way to make _real_ constants?

I find it a little misleading and confusing that while Elixir boasts immutability, that immutability is buried between layers of mutable abstractions. For example, if I have the code: foo = {:cat, "...
0
votes
2answers
55 views

Phoenix.Router.NoRouteError for assets

in elixir i try to create project under umbrella with this command mix phx.new my_project --umbrella in apps directory try to install phoenix project with this command mix phx.new phx_project --no-...
3
votes
2answers
44 views

Is with and try/rescue can be same in elixir

I am trying to handle an error coming in a result of an HTTPoison.request! with try do %{"session_id" => session_id} = ElixirDropbox.Files.UploadSession.start(client, true, image_save_path) ...
0
votes
1answer
32 views

Elixir's GenServer handle_call, handle_info, handle_cast not being invoked

I've implemented a simple Application -> DynamicSupervisor system where the Application creates a single DynamicSupervisor on startup and then sends a message to it to start some work. The problem is ...
0
votes
0answers
37 views

How do I create a single controller for two models?

I have two controllers for my MVC structure project. One is going to show a list of expenses and other lists of open sources but I have two different routes for that. How do I create a controller for ...
4
votes
1answer
43 views

ElixirLS debugger unexpectedly stops when used with Phoenix and VSCode

Trying to debug my Phoenix project in VSCode using ElixirLS. The launch config is defined as { "type": "mix_task", "name": "mix phx.server", "request": "launch", "task": "phx.server", "...
2
votes
1answer
34 views

Adding text to an image with Elixir Mogrify

I'm having trouble with the Mogrify package in Elixir. I have an image that I want to add text to. For some reason the image will open and save a copy without any issues but I can't get the copy to be ...
0
votes
2answers
44 views

In Elixir/Phoenix, what is the correct/best way to iterate through an EctoEnum.Postgres for a select input?

We have the following enum: defmodule PricingEngine.Pricing.ProductCategoryEnum do use EctoEnum.Postgres, type: :product_category, enums: [ :shoes, :apparel, :...
0
votes
1answer
40 views

Running multiple process in parallel elixir

I am using GenStage and starting a few processes through it. The code bit which is starting the process: defp start_snapshot_extractor(config, id) do config = Map.put(config, :id, id) case ...
0
votes
0answers
28 views

How to solve HTTPotion conn_failed intermittent error

Sometime I got intermittent error%HTTPotion.ErrorResponse{message: "{:conn_failed, :error}"}. headers = ["Content-Type": "application/json"] HTTPotion.post(<URL>, body: body, headers: headers, ...
0
votes
1answer
34 views

(Ecto.Query.CompileError) Tuples can only be used in comparisons with literal tuples of the same size. - Elixir

Where I'm at For this example, consider Friends.repo Table Person has fields :id, :name, :age Example Ecto query: iex> from(x in Friends.Person, where: {x.id, x.age} in [{1,10}, {2, 20}, {1, 30}...
0
votes
0answers
19 views

Upgrading Elixir project with Edeliver error: {:no_matching_relup, '0.1.0+35132c2', '0.1.0+ba8eb26'}

I am trying to upgrade my Elixir application with edeliver upgrade, but an error appears: {:no_matching_relup, '0.1.0+35132c2', '0.1.0+ba8eb26'} In cmd: mix edeliver upgrade production --verbose --...
0
votes
0answers
17 views

How to login in elixir ejabbered application after user register?

I have a elixir application with ejabberd server in it. When I start the application ejabberd server starts along with the elixir application. Then I registered 2 users at the host localhost. I sent ...
2
votes
1answer
39 views

In Elixir, Is it possible to modify mix format to make square brackets around final keyword lists mandatory?

Hold a strong belief that explicit is better than implicit, I really dislike that mix format removes the optional square brackets from the final parameter of a function when that function is a keyword ...
0
votes
0answers
17 views

Arc Ecto - Uploading to S3 from a remote URL returns a SignatureDoesNotMatch error

In arc_ecto, why do I get a SignatureDoesNotMatch error when uploading a file from an external URL to my S3 bucket (e.g. File.upload_file(%{"attachment" => "http://sample.com/file.pdf"}) ? I ...
0
votes
1answer
27 views

What do the on_delete options in Ecto.Migrations.references/2 do?

The Ecto documentation describes the options available to references/2, but does not document what those options do. The options available are: :nothing :delete_all :nilify_all :restrict What do ...
4
votes
2answers
89 views

What is the maximum number of child processes a supervisor can supervise?

Is there a maximum number of child processes a supervisor process can supervise? I'm coming from Elixir, but I imagine the limit (if there is one) would be inherited directly from Erlang.
-1
votes
1answer
53 views

How to get an access token from Google without an api library?

I am working on an Elixir Phoenix web project where I want to interact with Google's Indexing API. Google uses OAuth2 to authenticate api requests and actually has a decent documentation on this. ...
0
votes
2answers
32 views

How to pass link options to the PhoenixHTML link with this setup

I'm currently doing a partial template for any table with search fields. I need to generate passed from controller function names with options as links in my template. I have already tried solution I ...
2
votes
1answer
28 views

How can I update or insert multiple rows with ecto? (Upsert)

How can I either insert or update multiple rows with different values using Ecto with Postgres? If I have a schema/struct: %Counter{key: String.t(), count: integer()} How can I insert or update ...
0
votes
0answers
26 views

Absinthe call middleware before resolving parent

Background I'm working on a proof of concept Absinthe middleware that allows me to specify permissions required for a field in the schema, gathers all the required permissions for a query, check all ...
0
votes
0answers
30 views

Ecto raw query string interpolation not working

The string interpolation fails with this query: Ecto.Adapters.SQL.query!( MyApp.Repo, "CREATE INDEX zip_code_trgm_idx ON $1 USING GIN (zip_code gin_trgm_ops);", ["locations_zipcodes"] ) [debug]...
0
votes
2answers
51 views

How to round to the next 1000 value?

I want to round to the next 1000 value, always rounding up. Example inputs: 1 -> 1000 440 -> 1000 1001 -> 2000 14399 -> 15000 108 030 -> 109 000 I can only find a Float.ceil function ...
3
votes
2answers
47 views

How to differentiate errors in Elixir's `with` macro?

Often I have code that uses the with macro to ensure all the required data is available before proceeding, but I want to have more fine-grained errors to determine precisely why it failed. Using an ...
0
votes
0answers
19 views

exq_ui exiting in production server

I am trying to run exq and exq_ui in my prod environment, I am getting the following error - {:info, ["Application ", “exq_ui”, " exited: " | “exited in: ExqUi.start(:normal, [])\n ** (EXIT) ...
0
votes
1answer
34 views

Adding an item to a many to many association using Ecto

I have a 'boards' module that has an association to 'users'. I want to simply add a user to the 'users' assocation. schema "boards" do # ... many_to_many :users, User, join_through: "...