["Admin": "admin", "User": "user"]
This is actually a keyword list. It's a list of 2-element tuples. It's syntactic sugar for:
[{:Admin, "admin"}, {:User, "user"}]
Note that the keys are atoms, not strings.
To create that using Enum.map, you want to return a tuple from your enumerator function, of the form {key, value}
.
More info here: http://elixir-lang.org/getting-started/keywords-and-maps.html
This is not a for loop. This is a list comprehension. It's like a for loop on steroids. You want to check out this link for more details.
They are working on it. Last I heard that they were figuring out a way to apply back pressure to avoid messages piling up at a bottleneck.
I also like to point to: Enumerables and Streams, it gives a nice overview of how the pipe operator can be used to do lazy evaluation.
Erlang and Elixir are, at least in my opinion, superior choices for concurrent and distributed programming.
I haven't been able to find anything in Haskell that would support code reloading in the same fashion that the BEAM (Erlang VM) does, nor anything that enables as fine-grained fault tolerance as Erlang has without requiring you to write very defensive code. From what I gather, Haskell's preemptive scheduling is also somewhat unfair compared to BEAM's, and it only has thread-local GC (that is, OS threads) rather than per-spark.
I'm not sure how well Cloud Haskell works. From a cursory glance, it seems pretty neat and seems to display good performance. I think you'd still run into some of the issues above, though.
I think Clojure (or the JVM in general) is in an unfortunate position: Implementing lightweight threads as a library within a virtual machine is almost never a great idea. My experience has always been that it leads to inferior performance compared to supporting lightweight threads directly in the virtual machine. Then there's the whole issue of accidental state sharing that both Erlang and Haskell simply prevent.
I will say this, though: For local parallelism, I'm fairly confident Haskell and Clojure would outperform Erlang. You can certainly do parallel programming in Erlang, but it's really designed to deal in concurrency, and keep in mind that these two terms mean different things.
We prefer the use of doctests in crutches (when applicable), since it lends itself nicely to the design pattern. They run like normal tests. 'mix test' is showing over 150 tests.
http://elixir-lang.org/getting-started/mix-otp/docs-tests-and-pipelines.html#doctests
Yes - 10k websockets/channels as it was 1:1 ratio. The server used for testing was Digital Oceans 5$ server, which has 1GB of Ram and 1vCPU. And it was basically a 'worst case' load, in which all Players matched with around 50% of other players, which in practise would be a bit much. I believe we hit around 500mb of ram usage, and actually hit a File Descriptor wall, which we stilll need to fix, rather than a memory wall.
&
is called the capture operator, it's a different way to create anonymous functions.
&String.length/1
is the same as &(String.length(&1))
is the same as fn x -> String.length(x)
. And yes, it means use the function length
with arity 1
from the module String
(and pass that argument too while you're at it).
More info: http://elixir-lang.org/docs/stable/elixir/Kernel.SpecialForms.html#&/1
I recommend: http://elixir-lang.org/getting-started/basic-types.html#anonymous-functions
I have not learned Erlang, but am familiar and comfortable using the erlang stdlib/dist modules from within elixir.
http://erlang.org/doc/apps/stdlib/
Many Erlang modules have not been wrapped as elixir packages, and for good reason, it's totally overkill.
I've been using the Erlang zip module in a recent project for example. To accomplish certain things in elixir it is recommended to use the stdlib erlang module from within elixir.
http://elixir-lang.org/getting-started/erlang-libraries.html
Not at all!
You can get started today by reading the excellent official guide or one of the numerous books.
Not an expert, but Erlang (with which Elixir shares a VM) is generally not used for parallel computing (in fact, Joe Armstrong, one of the creators of Erlang, specifically says in his book that Erlang isn't meant for fast numerical computations), rather it is used for applications where concurrency and responsiveness are advantageous. If you want something with good support for parallelism, more targeted at scientific and mathematical applications, you might look at Julia (http://julialang.org/).
Not to say you couldn't use Elixir, it just might not be the best choice for your use case (from how you describe it).
I'm working on a new web analytics tool. So far super happy I decided to go with Elixir/Phoenix for this project, I got the MVP done very quickly. Next I'm switching gears to marketing, design and copywriting but I also have some really cool features planned that I cannot wait to start coding :)
Just launched the beta yesterday, check it out: https://plausible.io/
This is the most common question about Elixir syntax :) There is a separate namespace for named functions and variables, so you can have anonymous function and named function with the same name. Without dot, you won't be able to know, which one to invoke.
More elaborate version of the answer by language creator: https://groups.google.com/forum/#!topic/elixir-lang-core/HzUEAVmbD00
According to the docs for Supervisor.Spec, the only current difference is the value passed for the :shutdown
option.
A supervised child defined with the worker
spec is given 5000ms to shutdown before being killed; the supervisor
spec sets a timeout of :infinity
, allowing as much time as necessary for the child to shutdown - including shutting down its own supervised children.
This is a rather complicated area about which entire books can be written, but here is the gist of it.
An OTP application's head is a special application process. Management of application processes involves a different set of options to describe what should happen when the application process crashes. (see the Documentation for more info). Generally this means either doing nothing, or crashing the whole node which can then be restarted by the OS should you desire it. This is all in line with the 'let it crash' philosophy.
The way you protect against this sort of thing happening is you run multiple nodes, hopefully on separate pieces of hardware. Then one node crashing doesn't crash your entire service.
Elixir is fairly slow for single-threaded tasks. All BEAM langs are. But with NIFs or calling out to other commands, thats not really a problem.
An app I'm working in has a simple Nim program that handles a particularly complex but single-threaded task. Elixir spins up a new Task whenever the program would be invoked, calls it, and when it receives a response, sends some emails and does some other things. The Nim program is substantially faster than a native elixir implementation.
If you have existing C libs, or can expose a C-style interface, NIFs are even better:
https://andrealeopardi.com/posts/using-c-from-elixir-with-nifs/
It depends on your needs. GenStage may be overkill for what you are doing. It sounds to me like you want some sort of simple cron job to run every 10 seconds and do some relatively simple job processing. If thats the case, I would use this pattern outlined by Jose.
I would not put any sort of data gathering logic inside my Supervisor start logic. This could stop your entire app from starting up, and you'd lose the advantages of OTP. Repo.all() is a relatively safe function, but I wouldn't get into the habit of placing my logic there. You'd want to move that logic down into the GenServer or GenStage.
If that GenServer job begins to have issues of scale, I'd look into using GenStage. I'd start with the simplest solution first.
I did the same thing last year in a shell script and announced it on the elixir-talk mailing list but nobody seemed to care. Oh well, it works for me and that's what matters! :)
Looking for a technology company actually willing to embrace new technology? Join our team at LiveHelpNow, a recognized leader and innovator in customer service software. We have been running Elixir in production and contributing to the open-source ecosystem for over a year. To help us handle our accelerated growth, we are looking for a few more developers. Whether you are already a guru or just discovering Elixir, if you know why Elixir/Erlang is so great, we want to talk with you! On-site or remote. We offer competitive benefits, generous time off, a casual and creative work environment, free lunches, and many other rewards and perks. Contact us at https://www.linkedin.com/jobs2/view/81813623 and let's talk!
Going to plug Exercism, I've been going down the Elixir path and it's been good for stretching my brain to the fp concepts. There's an elm path as well (haven't tried it but it's next).
Homebrew has some support for it: https://brew.sh/2020/12/01/homebrew-2.6.0/
But I think it's still not 100%. Getting dev tools -- docker, homebrew, node, asdf -- running on M1 probably not going to be straight-forward.
How many workers are we talking about? 100, 100.000? If many, spread them over multiple supervisors.
Simply start an empty supervisor, and expose a public function called attach_child_process or whatever, in that function call http://erlang.org/doc/man/supervisor.html#start_child-2 http://elixir-lang.org/docs/stable/elixir/Supervisor.html#start_child/2
But be careful, you can only use simple_one_for_one supervisor restart strategy if you're appending children dynamically.
In handle_call({:add_message.... you need to capture the second parameter (from), and store it in the state. Then you can return noreply, as you are currently doing.
Later, when you are ready to reply, you can call GenServer.reply with the "from" that you captured here. Does this make sense?
It's described briefly here:
http://elixir-lang.org/docs/stable/elixir/GenServer.html#c:handle_call/3
"Returning {:noreply, new_state} does not send a response to the caller and continues the loop with new state new_state. The response must be sent with reply/2.
There are three main use cases for not replying using the return value:
To reply before returning from the callback because the response is known before calling a slow function. To reply after returning from the callback because the response is not yet available. To reply from another process, such as a task."
What you can do with your Cache module is have it use GenServer. You can then start the cache process as a child of your application's supervisor. With what you're trying to create, look into using the name
option that can be passed to GenServer.start_link
- your cache process can be registered with a name, allowing it to be accessed from any part of your code.
It seems to me that you started learning the language, you learned that recursion is how loops are done and you started implementing recursion all over the place. The first thing to know is that recursion is usually implemented in the same few ways and there are helpers which implement these patterns for you. For example, Enum.map is recursive under the hood, but it implements a very common structure where you just provide the mapping function.
GenServer is just a more rich, complicated Enum.map. It handles all of the recursion for you and you provide a set of callback functions which get called either for the lifecycle of the process, when a timeout occurs, or when a message is received. I would highly recommend reading up in the docs and guides on how GenServer works because you seem to have some fundamental misunderstandings.
You have tried to implement a one-shot GenServer which doesn't receive any messages during its lifespan. This is a common enough use-case that a helper been provided in the form of Tasks. You can start a Task as an OTP worker just like a GenServer or even do more fancy things with their supervision, but that is beyond my scope here.
Further, you seem to want to be transforming an external API call into an enumeration of elements. You should really consider wrapping this up in a Stream. Streams are, in part, designed for wrapping behavior like this to make it work like any other Enumerable. In particular, Stream.resource/3 is a good place to look.
Some combination of Task and Stream would better capture what you are trying to do here.
strings are double quoted.
iex(4)> is_binary 'abc' false iex(5)> is_binary "abc" true
char lists are single quoted
iex(6)> is_list 'abc' true iex(7)> is_list "abc" false
http://elixir-lang.org/getting-started/binaries-strings-and-char-lists/
Having become comfortable with both Erlang and Elixir, I am perhaps a bit surprised that there is much in the way of transition difficulty between the two. Unless one is metaprogramming or using the results of metaprogramming, the differences between Erlang and Elixir are trivial. Everything I say here should be prefaced by saying that I think that maintaining a project with both Erlang and Elixir code sounds like much more work than either staying with Erlang or figuring out Elixir.
Mix can compile your Erlang files in addition to your Elixir files (docs here). Erlang and Elixir don't exist in the same file. I haven't done it, but the capability is certainly there.
Modules in both Erlang and Elixir are functionally the same, they both are identified by global scope atoms, but Elixir modules use some sugar that becomes exposed when you call them from Erlang. Elixir transforms Module.Name into the Erlang-syntax atom 'Elixir.Module.Name'. To call its function foo in Erlang you call
'Elixir.Module.Name':foo().
Since Erlang modules are almost always just lower-case atoms, in Elixir you call them as
:module.foo()
Erlang has good support for TCP connections with the :gen_tcp
module (unsure of what protocol IRC uses...). The Elixir OptionParser http://elixir-lang.org/docs/stable/elixir/OptionParser.html is a good tool for CLI tools. You'll likely want to use one or more GenServers http://elixir-lang.org/docs/stable/elixir/GenServer.html as well to store state and information. Look at Task and Agent for more generic versions of a GenServer.
If I'm not mistaken, exs files compile in memory just before being run. There wouldn't be much difference unless your exs file was large enough to impact ram as it was compiled in memory.
> The file will be compiled in memory and executed, ...
This keyword is translated to a require <Module>
and <Module>.__using__(opts)
calls for a specified module:
http://elixir-lang.org/docs/stable/elixir/Kernel.html#use/2 https://github.com/elixir-lang/elixir/blob/v1.0.2/lib/elixir/lib/kernel.ex#L3256
What concerns me I'd prefer to not overuse this macros as it makes code harder to read. Ecto and Plug are good examples of macros overusing. But it's just my opinion on the topic.
Checkout www.phoenixwebframework.com for guides in building channels. Channels work seamlessly for basically any client. You can find info about clients built for iOS and Andriod here: https://groups.google.com/forum/#!searchin/phoenix-talk/andriod/phoenix-talk/UOuEpHvB__k/eToGbOrQ4RUJ
From the official documentation: > Phoenix currently ships with its own JavaScript client. iOS and Android clients have been released with Phoenix 1.0.
I'm from mobile so I cannot help you further, but I think they should be on the phoenixframework organization on github.
edit: i cannot find ANY pointer on the official documentation on where the repos are. googling around i found this repository, linked by /u/chrismccord in the phoenix google groups. If those are the official one, I have no clue at this point. Asking someone more knowledgeable to pitch me and correct me if I'm wrong.
I'm working in a company that's developing https://semaphoreci.com - a continuous testing and deployment platform and we're hiring developers willing to work with Elixir and/or Ruby - http://renderedtext.com/jobs/2015/lead-engineer/. Let me know if you have any questions about that. Cheers.
I know you asked for projects, but you while you're trying to come up with some ideas, you can also practice by doing the Elixir exercises on Exercism. There are some nice things about doing them: 1. They force you to come up with your own solution. 2. Assuming others participate, you get feedback on your submitted exercises. 3. You can view the solutions others came up with. I've done some Clojure and Haskell exercises and got great feedback.
&Task.async
"captures" the function, allowing you to pass the named function as an argument to Enum.map
.
&1
is notation for the first argument passed to the anonymous function.
See documentation here: http://elixir-lang.org/crash-course.html#partials-and-function-captures-in-elixir
Additionally, I would opt towards writing anonymous functions with named arguments, as it makes things a little easier to understand (in my opinion).
fn index -> calculate(index) end
This looks like a much fancier version of something a built a week or two ago to cluster my nodes on AWS. I used ex_aws to query for EC2 instances with a particular tag, then Node.connect/1 to them.
Perhaps streams and function "repeatedly/1" may help get you started. You can take 50 and pipe that result to another (stream) function.
http://elixir-lang.org/docs/stable/elixir/Stream.html#repeatedly/1
When you are calculating the info_hash you can not rely on the data generated by re-encoding the info-dictionary. Not every bencoder sort the key/values the same when they encode dictionaries, so you need to get this info from the torrent file as it was encoded.
And I don't think there is any need to base16 encode the pieces data—but I could be wrong about that, I haven't gotten to the point where I verify pieces in my own implementation, but I have a feeling that this could be something specific for the Node-implementation and how buffers work in Node.js.
You could look into structs
for generating a nice data representation of the parsed torrent. http://elixir-lang.org/getting-started/structs.html
I hope that helps.
The above link does 404 for me, so here is the correct one: http://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html
You'll find the reason for single quoted strings on that page:
> In practice, char lists are used mostly when interfacing with Erlang, in particular old libraries that do not accept binaries as arguments. You can convert a char list to a string and back by using the to_string/1
and to_char_list/1
functions [...]
So it's interoperability with Erlang libraries that makes this distinction important. The double quoted ones are needed for binary pattern matching, so Elixir needed both.
I think the biggest difference is that ElixirSips started when Elixir was still pre-1.0, so some of the introductory videos are now outdated and old.
LearnElixir.tv is more expensive and has less content. IMO you're better off doing the getting started guide on elixir-lang.org (which has more info than LearnElixir.tv and is free) and then switching over to ElixirSips which has way more diversity beyond just the language itself. For $9 theres over 200 videos, thats a good deal!
This is (IMHO) the best one: Elixir In Action. But everything in this page in very good. :)
EDIT: haven't read the second bit the first time, sorry. I'll try to respond. No, channels are NOT the solution to safe concurrency, neither is in general functional programming. Channels in Go implements a messaging pattern that you could use to write safe code, but this does not protect you from deadlock¹ etc. And functional programming is built on value passing instead of reference passing (you do not pass the variable, you pass only it's value), but it does not protect you from side effect as a whole. In fact, Erlang solve this problem with the OTP and his internal scheduler. If you adhere to the OTP standards, your are quite good to go.
¹ go has tools for detecting race conditions.
Yes. Variables in a case statement "head clauses" are not bound to the upper "context", but body clauses are. You can read about this in the docs here under "Variables Handling":
http://elixir-lang.org/docs/stable/elixir/Kernel.SpecialForms.html#case/2
Note that it should be more idiomatic to assign to the result of case rather than within the body of the function.
You're misunderstanding what require
does. It does not transfer bring functions and macros into the current namespace, it instead allows you to call macros from other modules in the namespace.
http://elixir-lang.org/getting-started/alias-require-and-import.html#require
What you are describing is an an unqualified import
, which I agree, is less than ideal. However, you can just import the needed functions quite happily, like so:
import List, only: [duplicate: 2] x = duplicate(:ok, 10)
Or, better yet, use alias
, which gives you a shorthand for qualifying modules, rather than polluting the namespace at all.
alias My.Long.Module.Name x = Name.foo()
alias My.Long.Module.Name, as: N x = N.foo()
I just started reading through your article, and saw this:
> Originally I was hoping to be able to pass in the already defined arithmetic functions in Elixir such as Kernal.+/2 but I was unsuccessful in passing the function without it being evaluated.
What you want is the Capture operator which looks like:
iex(1)> fun = &Kernel.+/2 &:erlang.+/2 iex(2)> fun.(2, 2) 4
So to use any function with your Elisper.eval/1
function, you simply have to it like so:
iex(1)> Elisper.eval [&Kernel.+/2, 2, 2] 4
or since Kernel is imported by default, this would also work:
iex(1)> Elisper.eval [&+/2, 2, 2] 4
That would negate the need for your native_ops
map and greatly expands the support for operations in your implementation. An actual parser would just need to map keywords to built-in functions with the proper arity.
The elixir tutorial touches on this sort of thing starting here if you want a look at it from the ground up. Seems to me like a better place to start than diving straight into an existing library, but that's just my perspective.
The article talks about how Enum.reduce has worked, but Enumerable.reduce is a different beast which supports halting and suspending to a sort of continuation function.
http://elixir-lang.org/blog/2013/12/11/elixir-s-new-continuable-enumerators/
FYI, I was confused/annoyed by the Regex library, until I found that the String library has many corresponding functions with string as the first parameter.
http://elixir-lang.org/docs/stable/elixir/String.html#replace/4 http://elixir-lang.org/docs/stable/elixir/String.html#match?/2 Etc...
EDIT: Should have read the rest of the thread! So redundant!
People from Ruby can actually read Elixir.
#sarcasm
But also... Macros! It is rare to have "true" macros available in a language that is not homoiconic.
It's possible to specify the timeout on assert_receive http://elixir-lang.org/docs/stable/ex_unit/ExUnit.Assertions.html#assert_receive/3
You can also just unit test the handle_call, handle_cast functions and have no timeouts at all. Just test the input/output according to the specified behaviour.
On integration tests for async execution you will find timeouts and sleeps a common approach out there.
P.S.: there's a typo "aysnchronously"
Nope, you don't need to use PostCSS directly. You can see more details on the documentation page. It is recommended to use PostCSS directly if you have an involved CSS pipeline. For this generator I wanted to target the simpler case.
I'm having fun building a stub server, Stubbex. Among other things, it can:
I've already written a simple frontend test using it and Cypress for an app that would otherwise need VPN access to develop; works like a charm.
I was thinking the same thing.
If you want to see frameworks pulling this at their finest, check the super popular PHP framework, Laravel's, new Elixir tool which employs a command called mix
to manage a couple preconfigured gulp
tasks (JavaScript/npm). I get the don't-reinvent-the-wheel mentality, but a lot of these JS build tool libs do nothing more than wrap C libs that could just be rewrapped in the framework's language. The worst part about Laravel's Elixir mixing is that it's likely going to add a lot of noise to Googling for Elixir's mix
.
JEG and Bruce Tate are about to release a new book (in beta) that might be worth checking out for you.
> But if I need a command-line utility to move files around on my system, I wouldn't use Phoenix.
Totally agree! But I also wouldn't use Java for command-line, either. Similarly to Elixir, it has to start entire virtual machine, which makes it too slow for one off command line utilities, but perfect for long running systems. And it still became mainstream.
> But if you're not working on those classes of problems, Elixir can look overly complex.
It is still easier than OO programming though. There is a study that shows, that it is easier to teach people functional programming first. Like in this course: https://www.coursera.org/course/proglang Elixir even with OTP is less complex than Java.
The problem is, that Elixir is so different, that it looks more complex and overwhelming. However Akka and Reactive Programming movement make actor model more and more popular. We will see, what comes out of it :)
If this is some sort of struct it is good practice to use a `new` function and then you could just use a guard clause:
defmodule Phone do
defstruct :number, :state
def new(number, state)
when state in [:ringing, :voicemail, :talking, :inactive, :hold do
%__MODULE__{
number: number,
state: state
}
end
end
If you are accepting user input I would just use Ecto Changesets & Schemas.
If you are actually modelling a state machine you could look into <code>gen_statem</code> which is very nice for modelling state machines.
Indeed. I found I still want to drop Node though. Node's sibling Deno is just a single executable sitting on PATH that can pipe css through various ES modules on CLI including PostCSS with plugins and rust/go tools.
deno run postcss/import.ts -i "app.pcss" | tailwindcss -i - --minify > final.css
And if tailwindcss ever gets ported to Rust? Can switch without a care in the world. Don't like cssnano? Can use esbuild instead and have it done 2x faster and then perhaps gzip-it.
deno run postcss/import.ts -i "app.pcss" | tailwindcss -i - | deno run postcss/autoprefixer.ts | deno run "https://deno.land/x/esbuild/mod.js" --loader=css --minify | deno run compression/gzip.ts > final.css
Or I can write the whole thing in a single `.ts` file including watchers. Separation of concern works magic here.
As of Tailwind 3.0, you can also use their CDN link and specify your configuration and theming in a script tag. Another way to avoid node/NPM entirely! https://tailwindcss.com/docs/installation/play-cdn
Just launched our Elixir project today! It's a time sheet automation app. Check it out on Product Hunt and give us an upvote :) https://www.producthunt.com/posts/clockk
These docs should get you pointed in the right direction: https://stripe.com/docs/quickstart
There's a section on declined payments so I would pattern match on the response when trying to charge the card and do things based on which pattern matched (success or failure).
So let’s assume you have a CI process that uses mix release to build a tarball. You need to get this tarball onto each of your web nodes, and in a controlled fashion, upgrade to the latest release, typically 1 node at a time.
The mix docs say:
> you can assemble the release at the end of your CI/CD pipeline by calling MIX_ENV=prod mix release and push the artifact to S3 or any other network storage. To perform the deployment, your production machines can fetch the deployment from the network storage and run bin/my_app start.
> Another mechanism to automate deployments is to use images, such as Amazon Machine Images, or container platforms, such as Docker.
They leave it up to you to get the release from your build server onto your production machines. Is there some mix deploy
task that I’m missing?
> Why would you reconfigure your load balancer every time you deploy? There is no need to do that.
Rolling updates allow zero downtime deploys. You don’t need a container orchestrator to do rolling updates, but it’s a built in feature of Kubernetes, ECS and the like.
Great! Concurrency is definitely an interesting topic in Elixir, and I'd love to learn more about it.
FWIW, my background so far is mainly from reading "Programming Phoenix" by Chris McCord. He goes into some detail on GenServer
and Supervisors, but even after working through those chapters, I still don't feel super confident about my understanding of it.
Also, I think it would be very interesting to compare Elixir's approach to concurrency with other languages. For instance, it seems to me that using spawn
in Elixir is somewhat similar to scheduling a callback in JavaScript using <code>process.nextTick()</code>.
In your article, you've used spawn
only to print something, is it possible to have that return a value, too? Or does that require a different approach?
Finally, you didn't explain at all what the Actor model is about and how Elixir implements it. The book I mentioned doesn't say anything about Actors, so I'd love to read something that explains that in more detail.
Thanks for your work, and I look forward to reading your next post.
Thanks for the suggestions, I see your point of view on what to use, however, as I said in the post, I'm trying to get better in elixir and, it is much simpler than anything with JS, I remember that even when I had a decent knowledge of this stack, I would spends hours fixing errors, dealing with deprecated deps etc., but, I will check out render.com more
Thanks - Yeah I think using supervised GenServers to represent the agents and using another GenServer to represent the "stage" makes for a pretty easy to maintain parallelizable game architecture.
Writing an Agar.io clone would be pretty fun - if you do it definitely drop me a DM and I'd love to look it over with you/let you see how I structured this game/work on it a bit.
I found the Elixir path on exercism.io to be a very effective and practical hands-on way to get thinking about functional programming and writing idiomatic Elixir code.
http://exercism.io/languages/elixir/about
Being able to review code and ideas from other devs on that site attempting to solve the same problems was a big help as was all of the direct feedback from those same devs when they commented on my own code submissions. Best of luck whatever path you take.
I don't know if it proves anything but Elixir 1.1.1 is (by far) the most downloaded version of Elixir on Chocolatey NuGet (https://chocolatey.org) so far.
It's not even close. It's averaging slightly more than 18 downloads per day. Next closest was just above 12 downloads per day. That said, there are always more downloads of the latest version right after it's released so the number is probably skewed upward. Still it's a good sign for Elixir adoption.
As a part of Elixir community, I can't generally compare two languages good, but I can tell you that this task can be possibly very good implemented in Elixir (but it will be really hard).
https://flussonic.com/ - provides general solutions for video streaming/processing/communication - is totally and fully BEAM based.
Great Post Thanks a lot it helped me a lot I am also going to share it to my friends and over my social media. Also, Hackr.io is a great platform to find and share the best tutorials and they have a specific page for Elixir
This might be useful to your readers: https://hackr.io/tutorials/learn-elixir
If you've correctly forwarded TCP traffic on 4000 from your external IP to your local machine, you should be able to get it working. However, there are any number of weird issues you run into trying to expose a LAN device to the outside world if you're not using an internet provider and plan specifically tailored to hosting. The most common issue is that your ISP may be blocking traffic on certain ports on your modem, so even if your router is configured correctly the traffic may not even be making it there.
If you want, you can try a hosted service like ngrok that tries to circumvent common issues by proxying all traffic through their own servers, but your mileage may vary. Generally, using a dedicated remote host is the path of least friction.
Ah, I remember now -- a quick search jogged my memory. The process I'm talking about is the one mentioned here: "Specifying ImagePullSecrets on a Pod"
> This approach is currently the recommended approach for GKE, GCE, and any cloud-providers where node creation is automated.
It's more of a yak shave to set up, but once done, I'm not relying on any google-environment-specific k8s support. Same config works for slow e2e tests, etc.
Agreed re: not disheartening newcomers and using local docker in minikube!
Are you committed to using LiveView for this particular feature? I don't know of any Elixir specific PDF solutions (and don't see any in the other comments either), but I've had success building PDF viewing functionality using https://mozilla.github.io/pdf.js/ on the client-side.
> elixir-playground
Yesss, I like this approach as well. Writing tests is a great way to take notes.
I've been thinking about the "heaviness" of side projects too, and my conclusion is to keep the side projects as small (and demo-able) as possible. Some of my hobbies (like making games in PICO-8) encourage this miniature approach to projects.
What do you mean with "programs"? Applications that run on terminal? Applications that user interacts directly? Any code that encapsulate a state?
It is important to define that, since elixir is fp and the examples you gave are imperative and oop. Most of the things you would expect from a language like java, python, ruby, can't be expected from elixir/erlang. First of all creating an elixir application are related directly with OTP, since an application is an abstraction inside the OTP principles. To create an out of the box application in a fast and direct manner, I can suggest you this "how i start" written by José Valim: http://howistart.org/posts/elixir/1
The Getting Started guide is really good, and if you do the Mix and OTP section will help to understand more: http://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html
Yes, all your modules that are in the main project directory or external dependencies as specified in your mix.exs
file will be imported and made available throughout your project. You can find out more about how to customize paths (for builds, compilation, load paths, etc.) here.
I threw this together, it works with Maps. Includes a couple assert/refute tests.
Once you convert the json to a map, this should theoretically work for determining if any nested value exists in the nested map.
Will leave as an exercise for reader to make doable for any key/value enumerable. ;)
One way of doing this is to start a supervised task like in the getting started guide: http://elixir-lang.org/getting-started/mix-otp/task-and-gen-tcp.html#task-supervisor
That way your genserver is basically just responsible for delegating work out, you could even have the response sent directly back to the client.
def add_message(pid, message) do # Call your genserver to get a reference to listen for ref = GenServer.call(pid, {:add_message, self, message}) # Have client wait for response receive do {^ref, data} -> data end end
No need for apologies! :) Of course function reference is a more correct description than lambda function in a stricter sense.
But if we were to define it precisely, is it really a reference? Sure, it's a good intuition for people familiar with similar concepts from other languages but I have no idea how &f/n
is implemented inside the compiler (will have to dig into the source code to check). The documentation calls it simply <u>function capturing</u>.
Regarding learning and terms, I think people usually get confused with lots of similar terms but learn the difference with experience.
First thing, your spacing is way off. Idiomatic Elixir uses 2 spaces and no tabs, check your editor is setup right.
Second, it seems what you want from your PubIpMon.CLI module is a mix task. Read about mix tasks here.
Also, I suggest you keep your functions which cause side effects (in this case the ones that do IO.puts) to a minimum so that those functions are easier to test.
Try looking at using the new with
keyword in Elixir 1.2 if you're brave and remove all the IO.puts from all functions except PubIpMon.Comparator.compare/2
.
You might find it best to start by taking a look through the official Getting Started documentation (http://elixir-lang.org/getting-started/introduction.html), if you haven't already. It's really good; especially once you get to the 'Mix and OTP' section.
To add to these great answers, at the point you do need to learn the Erlang syntax (which will happen sooner or later), a good place to start would be on this page.
In the function head
is a single element of a character list or binary. For these + is defined. In iex you are trying to add on a binary (the whole string). Try something like <<110+n>>
or [110+n]
and you should see the expected output.
Also have a look here.
Edit: You can even do it like this to be more epxressive about the "n": <<?n+n>>
.
I think by 'umbrella' you are talking about an 'application' as it is understood in the Elixir/Erlang world. When an OTP application is used in a project, it launches an Application process which supervises several other processes which do the actual work. These supervisor trees are essential to the most important parts of Elixir and while it can take some time and experience to grok them, they are the primary reason to use the language and VM.
ExIrc seems to be set up like a fairly compliant OTP application. What you need to do is set up separate clients and event handlers for your 'listener' and 'whisperer' connections and then have the listener pass messages to the whisperer. How to do this is a bit involved, but a good place to start is the documentation on GenServer; pay particular attention to the bit about Client / Server APIs.
If you really want to get moving on this sort of programming, I am unfamiliar with any Elixir-centric documents which are of an appropriate level. There is, however, the free and very good learn you some Erlang for great good. You have to bend your brain a tiny bit around the Erlang syntax, but it will walk you through the concurrency model and how OTP processes work.
I only had a quick peek, but how about putting your account-credentials (eg. username, password in mailer.ex) into the configuration (see)
you should study the enum functions:
http://elixir-lang.org/docs/master/elixir/Enum.html
"Reduce" is pretty powerful and fairly important (although not COMPLETELY trivial) to understand (IMHO). It's like "inject" if you've used Ruby, or "fold" if you've used Haskell.
I don't know of anything specific to JavaScript. Probably best to start working through the Elixir tutorials on the website: http://elixir-lang.org/getting-started/introduction.html Keep clicking through on the "Next" button; you'll get to a pretty good tutorial on Elixir.
Ubuntu has old version of elixir in repo. You can try to download precompiled packages or compile code yourself. Check info on http://elixir-lang.org/install.html I am using kubuntu 14.10 with compiled elixir version 1.1.0-dev
From https://parceljs.org/getting_started.html
parcel watch index.html
Starts watch mode and recompiles the changed parts of the index.html
dependency graph.
Edit: an example repo https://github.com/ben-pr-p/elixir-phoenix-parcel-example
I think you can avoid JS with frameworks like Yew. I've only done "hello world" with it so far though. Here is a tutorial.
> I initially had the general section centered, but it looked awkward (i suppose it still does) with only a single column.
Given that you are using SemantiUI, something like this (doc)? You could inline and center them. I have no idea if the result would be better (or any good), but may be worth a try. :)
I'm a huge Elixir fan, but I do want to point out that lambda on AWS may be a solve in the "if this thing gets big" scenario, both from a cost perspective and an architecture perspective.
Setting up either Distillery/edeliver or mix releases to do deployments to a vanilla Linux server running either Nginx or Haproxy isn't that hard either. That's how I deploy to vultr.com. It's a lot cheaper than other options.
I used to use DigitalOcean all the time but recently I've switched to vultr.com. They are similar to DigitalOcean, but I've had less problems with them. Their pricing is similar to DigialOcean.
Gigalixir is also nice.
Those are not ADTs, those are interfaces, which are an unrelated type system feature.
Here's the docs I linked again on ADTs in TypeScript: https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions
> I didn't claim Elixir does not have it. Elixir's Structs implicitly introduce a meta tag with the struct name to the runtime. Structs are bare maps with that extra field after all, minus the protocol polymorphism maps get out of the box.
It sounds like you're now agreeing with me that we can have ADTs in Elixir and Erlang with no runtime modifications?
> This is possible because I handle the shape of the data at runtime without compile time knowledge of the types being used.
This is also possible to do at compile time, and is quite idiomatic in TypeScript. With TS you could write this same function, declaring that it takes an interface.
However, this function in Elixir, I don't think would be able to be expressed in TypeScript and checked at compile time:
def translate(%{x: x, y: y} = pt), do: %{pt | x: x*2, y: y*2}
It operates based on the shape but also returns the untouched data. (In TypeScript, you could do this without compile time guarantees by just declaring that the function returns any
, which is sort of equivalent to Elixir.)
Also, and this is where I'm not an expert, but I believe "row polymorphism" refers to my example (where the extra data is passed along) and your example is "structural subtyping".
All that said, I appreciated your post! I'm working on a typechecker for Elixir (using dialyzer specs, but with semantics more like rust/typescript), so it was right up my alley!
I recently replaced my custom Redis queue code (using the poplpush pattern[1]) with Broadway and the Redis adapter[2] (which uses the same pattern so no code change to push into the queue) and it was mostly quick and painless.
ETS is an in-memory store yes, but Redis is at its core the same thing. Redis has some features that can enable on disk saving of data snapshots, so if that's something that's important to you, you may need to hook into OTP's mnesia module (I'm stretching my erlang/OTP knowledge at this point so someone call me out if I'm wrong).
I was in a similar situation. Here are some tips I recommend.
Learn and practice with the pattern matching operator, =.
To some, it seems like just a simple assignment operator. Oh no no no. Pattern matching is border line magical. For example, you have a variable that is a map. You can easily pull out what info you need like such:
> %{title: title, id: id} = map
You now have two variables: title and id.
Moreover, you can pattern match on function parameters to take overloading to the next level!!
Using the map example, say you have an overloaded function that only deals with id's of 1:
> def dostuff(%{title: title, id: 1}) do...
> def dostuff(map) do...
The first function will match with only ids of 1, and the second function is just the fallback, or catch all for everything that isn't id 1.
Next,
Elixir is not pass by reference. There is no mutation of variables. So if you are working with enumerables, let's say you want to filter out all occurences of 1
in a list of numbers. Enum.filter(your_list_here, fn_to_remove_1s)
, your_list_here never changes. The function just returns a brand new list.
Finally,
Play around with the various functions the elixir comes with: https://devdocs.io/elixir~1.7/list
Map, Enum, and List are very helpful.
Hope that helped. If you have any questions feel free to message me. Always willing to help. Good luck!
The limit can be set using the set_limit()
function in Postgres (http://www.postgresql.org/docs/9.1/static/pgtrgm.html#PGTRGM-FUNC-TABLE). Unfortunately, there's no way to change the default easily, and it resets to the 0.3 on new connections.
Previously, I've solved this by setting the value I want after connecting, but Ecto doesn't have any callbacks or hooks on connect. I've made an issue here: https://github.com/elixir-lang/ecto/issues/599
Not ideal but here is the one I'm using in the photo https://www.amazon.ca/gp/product/B00DGTP57A/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1&fpw=alm
They are great for the ultrawides if you are okay with being able to adjust the distance
Hi kagux,
I'm planning to share interactive streaming sessions with you, where I show how you can apply the good practices of software development, such TDD, test-first-programming, Refactoring and Clean Code in order to learn a new programming language (e.g. Elixir), learn new libraries or frameworks (e.g. Plug o Phoenix Framework) and contribute to some Elixir open source projects (e.g. ex_debug_toolbar or other).
What I am doing right now is going in depth with Plug, I already made some open source contribution during the last Hacktorberfest event. I plan to move on by exploring something about the Phoenix framework.
I am looking forward to hit you on the elixir's slack, maybe there we can find other interested at this Twitch Channel. Do you think it could be useful to share my channel in the elixir's slack?
This may sound weird but for me the easiest way for me to wrap my head around functional design was to pick up a book that brought some functional ideas into my day job OO language(javascript). The book I picked up(https://www.amazon.com/gp/product/1617292826) made the switch to a functional language much easier. After reading it it changed how I programmed day to day with javascript and eventual was the reason I reached out to learn elixir because of how much functional design matched up with how I think.