Skip to content

Instantly share code, notes, and snippets.

View john-evangelist's full-sized avatar

Evangelista john-evangelist

View GitHub Profile
defmodule App.Implementations do
def of(key) do
with impls when is_list(impls) <- Application.get_env(:app, :impls),
{:ok, module} <- Keyword.fetch(impls, key) do
module
else
:error ->
raise KeyError,
message: """
:#{key} key is not defined in the implementations for application :app
@john-evangelist
john-evangelist / active_users.ex
Created April 3, 2019 05:32
Use behaviours to declare interfaces and decouple implementations from business logic
defmodule Project.ActiveUsers do
@behaviour Project.UseCase
def run(params, deps) do
deps[:repo].fetch_users(params)
end
end
@john-evangelist
john-evangelist / event.exs
Last active March 1, 2019 20:12
Grouping entries by date on Scala | Elixir
defmodule Event do
@type t() :: %__MODULE__{date: Date.t(), title: String.t(), content: String.t()}
defstruct :date, :title, :content
def group(events) do
events
|> Enum.group_by(fn event -> envent.date)
|> Map.to_list()
@john-evangelist
john-evangelist / pure-impure.md
Last active February 25, 2019 19:17 — forked from tomekowal/pure-impure.md
Pure vs impure

Pure vs impure and why should I care?

Some of the most important advancements in programming came from adding restrictions to the way we program. Famous article by Edsger Dijkstra Go To Statement Considered Harmful shows how introducing one statement into programming language breaks many nice properties of that language. goto gives us freedom and solves couple of simple problems like breaking from nested loops easily, but it can make programs very hard to understand. This happens, because we cannot look at two pieces of code in separation. The execution can jump to some other place in code or even worse: it can jump from other piece of code to here and We need to keep that in mind.

@john-evangelist
john-evangelist / ENV.md
Last active February 15, 2019 17:33
Idea of Documentation for declaring environment configurations

Service: Blog

<< Description >>

Thrid Party Dependencies

Thrid party depedencies used by this service:

| Service | Protocol | Documentation | Env Vars |

@john-evangelist
john-evangelist / webpack.config.js
Created January 4, 2019 02:13
phoenix webapck
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const paths = {
static: path.join(__dirname, "../priv/static"),
build: path.join(__dirname, "../priv/static"),
node_modules: path.join(__dirname, "./node_modules"),
@john-evangelist
john-evangelist / README.md
Created December 26, 2018 05:28
quick script to generate files
  • Create file on .templates folder at user home: mkdir ~/.templates/elixir && touch ~/.templates/elixir/module
  • Contents:
defmodule {{mod}} do
end

Usage: bob -tpl elixir/module -d ./person.ex -v mod=Person

Templates are based on handlebars rendered by aymerick/raymond

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const devMode = process.env.NODE_ENV !== 'production'
module.exports = {
entry: './src/main/resources/assets/js/index.js',
output: {
filename: './js/index.js',
path: __dirname + '/src/main/resources/static/'
},
module: {
@john-evangelist
john-evangelist / metals.log
Created November 28, 2018 16:33
semanticdb unresolved
warn  Unable to automatically connect to build server.
info  running 'sbt metalsEnable bloopInstall'
error Getting org.scala-sbt sbt 1.2.1 (this may take some time)...
info  downloading https://repo1.maven.org/maven2/org/scala-sbt/sbt/1.2.1/sbt-1.2.1.jar ...
info  [SUCCESSFUL ] org.scala-sbt#sbt;1.2.1!sbt.jar (1216ms)
info  downloading https://repo1.maven.org/maven2/org/scala-sbt/main_2.12/1.2.1/main_2.12-1.2.1.jar ...
info  [SUCCESSFUL ] org.scala-sbt#main_2.12;1.2.1!main_2.12.jar (6509ms)
info  downloading https://repo1.maven.org/maven2/org/scala-sbt/logic_2.12/1.2.1/logic_2.12-1.2.1.jar ...
info  [SUCCESSFUL ] org.scala-sbt#logic_2.12;1.2.1!logic_2.12.jar (883ms)
info  downloading https://repo1.maven.org/maven2/org/scala-sbt/actions_2.12/1.2.1/actions_2.12-1.2.1.jar ...
import akka.actor.ActorRef;
import akka.dispatch.*;
import org.jctools.queues.MpscArrayQueue;
/**
* Non-blocking, multiple producer, single consumer high performance bounded message queue,
* this implementation is similar but simpler than LMAX disruptor.
*/
public final class MpscBoundedMailbox implements MessageQueue {