Passwordless Authentication in Phoenix

There are tons of different approaches to user authentication. Passwordless or “magic link” authentication is very user friendly, relatively easy to implement, and sufficiently secure for most apps. This article is a step by step guide for implementing passwordless authentication in Phoenix.

Using Ecto.Multi to Group Database Operations

One of the cool things to come out of Ecto 2.0 is the module Ecto.Multi. It is designed to be a way to group database calls into a single transaction so that the group fails if one fails. In other words, it’s all or nothing. This takes care of the problem we see above. There are no multiple levels of nesting and the API is actually really nice to work with. Let’s take a look!

http://geoffreylessel.com/2017/using-ecto-multi-to-group-database-operations/

Genetic Algorithms with Elixir

Lately, I’ve been experimenting with genetic algorithms and ways to merge them with Neural Networks. The goal is to have Elixir based systems that can problem solve on their own. The post illustrates how GA’s can be used to solve problems. I show an example using a small project known as SPELLER.

http://tinyurl.com/zsll7au

Shameless plug: Check out @elixirstatus' other community project:

Credo, a new static code analysis tool that acts as a code linter, but also focusses on teaching coding practices and code consistency.

Twitter OAuth Authentication with Elixir and Phoenix

There are a few good examples showing how to use OAuth authentication in Phoenix and Elixir, but I wanted a solution which used a small amount of dependencies, and had the ability to make authenticated requests on behalf of a user.

Read more at http://headynation.com/twitter-oauth-elixir-phoenix/

Integration Testing Phoenix With Wallaby

Let’s write an integration test for Phoenix using Wallaby:

https://hashrocket.com/blog/posts/integration-testing-phoenix-with-wallaby

Protect Your Data with PostgreSQL Constraints

Ecto embraces database constraints as the correct way to guarantee consistency in your database. (I helped with that code.) But do you know how to use them?

I’ve recently updated Protect Your Data with PostgreSQL Constraints to show the power and flexibility of features like exclusion constraints.

Molasses - A feature toggling library for Elixir!

A feature toggle library for Elixir using redis or SQL (using Ecto) as a backing service. It allows you to roll out features to a percentage of users or alternatively groups of users.

https://github.com/securingsincity/molasses

Building a CQRS/ES web application in Elixir using Phoenix

Case study describing how I built a web application following a Command Query Responsibility Segregation and event sourcing (CQRS/ES) pattern in Elixir.

Maxwell: One HTTP Client to Rule Them All

Maxwell is a Elixir HTTP client which allow developers to customize its behavior with middleware. If you’re familiar with Faraday or Plug, then you’ll love it.

https:[email protected][email protected]

Shameless plug: Check out @elixirstatus' other community project:

Credo, a new static code analysis tool that acts as a code linter, but also focusses on teaching coding practices and code consistency.

Deploying Elixir Applications with Distillery

Dive into this high level overview of the process of deploying an Elixir application with Distillery.

Deploying Phoenix on Ubuntu with Gatling

How To for an automated Phoenix deployment on Digital Ocean

There aren’t many detailed posts on how to deploy Phoenix apps to production, yet. This article is a step by step description of what I did to ship my first Phoenix app. I hope it will be a handy resource if you are searching for an easy way to achieve an automated deployment to a single server and leverage hot upgrades.

https://dennisreimann.de/articles/phoenix-deployment-gatling-ubuntu-digital-ocean.html

Tips for Getting Started with Elixir & IEx

https://www.promptworks.com/blog/getting-started-with-elixir-and-iex

A few tips for getting started with Elixir and IEx. This is for people who have been looking for an easy way to get started or who aren’t that comfortable with IEX yet.

Discriminated unions (algebraic data types) in Elixir

Elixir already has product-type, tuples, which allow to aggregate several values in to one. But it lacks a sum-type, which allows to create a structure with a fixed set of values and guards all of them are handled. DiscUnion solves this.

With it, you can create a structure with a finite set of values, and have compile-time warnings if you try to use a wrong value or miss handling one case:

shape.ex:

defmodule Shape do
  use DiscUnion

  defunion Point
  | Circle in float()
  | Rectangle in any * any
end

solver.ex:

defmofule Solver do
  use Shape

  def calc_area(shape) do
    Shape.calc shape do
      Point in _        -> 0.0
      Circle in r       -> :math.pi * r * r
      Rectangle in w, h -> w*h
    end
  end
end

If there would be a typo in Rectangle in solver.ex or this line would be missed completely, app would not compile and UndefinedUnionCaseError or MissingUnionCaseError would be raised.

For more complete example see tennis kata example (which also creates a structure that does not allow creating invalid state of the game - thanks to using ADTs).

Measuring and visualizing GenStage/Flow with Gnuplot

http://teamon.eu/2016/measuring-visualizing-genstage-flow-with-gnuplot/

Follow-up to last post about tuning GenStage/Flow, now describing how to measure and visualize pipeline progress.

Elixir Phoenix App deployed into a Load Balanced DigitalOcean setup

I documented a high-availability configuration I did for a Phoenix app over DigitalOcean and I just published about it step-by-step. I am looking forward to learn more tips and tricks, so if you’re a seasoned Elixir developer with more experience, let me know how I can improve this setup in the comments sections of the post.

'New' Phoenix React Redux Starter Kit

I’m working on a ‘new’ phoenix starter kit, using react and redux for the front end. I use a fractal approche for the organisation of the react code.

I created 5 branches (4 branches + master). master is the base. The other branches contain : ecto, user support, multi language support, and user + multi language support.

You can have more detail about it here : https://github.com/rsilvestre/phoenix-react-redux-starter-kit

HTTP Streaming in Elixir

http://big-elephants.com/2016-12/http-streaming-in-elixir/

Storing Nested Associations with Phoenix Forms

http://blog.heartbeathq.com/storing-nested-associations-with-phoenix-forms/

Introducing CERBAS

CERBAS - A starting point API server and web proxy backed by redis data structure memory no sql database.

Clients connect to CERBAS by storing requests from any language in redis. CERBAS dispatches elixir functions.

Also includes a Plug based proxy server with some examples.

A plus is a cronjob function handler ( via crontab syntax like file).

It’s a starting point for your API needs ( customize it to fit your needs ).

Find it on GitHub

Tensor, the Vector/Matrix/Tensor library has reached v1.0!

With the recent addition of Numbers and some improvements of the documentation, Tensor now has reached version 1.0.0!

For people that do not yet know about it:

Tensor is a library that allows you to work with sparse Vectors, Matrices and higher-order Tensors, with the following nice features:

  • An implementation of the Access protocol, so you can do mymatrix[42][3].
  • It supports the arithmetic functions you would expect from vectors, matrices and tensors. These are implemented using Numbers, which means that they work on any numeric type.
  • What is even more, Tensor itself implements Numbers’ Numeric behaviour, which means that anything that does number arithmetic can now do (elementwise) vector/matrix/tensor arithmetic! It also means that you can nest matrices ad infinitum!
  • A sparse implementation: Only elements deviating from the default element of a data structure are stored. This means that e.g. a nearly-empty 10000x10000 element matrix takes up only a neglegible amount of memory.
  • While you can work with numbers, you can store anything inside: Using it as a representation of a game board (a matrix for chess, or a 3-dimensional tensor for a Rubik’s Cube), for instance, is something that is very possible.
  • Functions to rotate, transpose, transform, combine, separate, map over and reduce vectors/matrices/tensors.

Here are some examples from the Readme:

Vectors

iex> vec = Vector.new([1,2,3,4,5])
#Vector-(5)[1, 2, 3, 4, 5]
iex> vec2 = Vector.new(~w{foo bar baz qux})
#Vector-(4)["foo", "bar", "baz", "qux"]
iex> vec2[2]
"baz"
iex> Vector.add(vec, 3)
#Vector-(5)[4, 5, 6, 7, 8]
iex> Vector.add(vec, vec)
#Vector-(5)[2, 4, 6, 8, 10]

Matrices


iex> mat = Matrix.new([[1,2,3],[4,5,6],[7,8,9]],3,3)
#Matrix-(3×3)
┌                          ┐
│       1,       2,       3│
│       4,       5,       6│
│       7,       8,       9│
└                          ┘
iex> Matrix.rotate_clockwise(mat)
#Matrix-(3×3)
┌                          ┐
│       7,       4,       1│
│       8,       5,       2│
│       9,       6,       3│
└                          ┘
iex> mat[0]
#Vector-(3)[1, 2, 3]
iex> mat[2][2]
9
iex> Matrix.diag([1,2,3])
#Matrix-(3×3)
┌                          ┐
│       1,       0,       0│
│       0,       2,       0│
│       0,       0,       3│
└                          ┘

iex> Matrix.add(mat, 2)
#Matrix-(3×3)
┌                          ┐
│       3,       4,       5│
│       6,       7,       8│
│       9,      10,      11│
└                          ┘
iex> Matrix.add(mat, mat)
#Matrix-(3×3)
┌                          ┐
│       2,       4,       6│
│       8,      10,      12│
│      14,      16,      18│
└                          ┘

Tensors

  iex> tensor = Tensor.new([[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]]], [3,3,2])
  #Tensor(3×3×2)
        1,       2
          3,       4
            5,       6
        7,       8
          9,      10
            11,      12
        0,       0
          0,       0
            0,       0
  iex> tensor[1]
  #Matrix-(3×2)
  ┌                 ┐
  │       7,       8│
  │       9,      10│
  │      11,      12│
  └                 ┘

You can find it on Hex.pm and on GitHub.

And here in the Elixir Forum.