Skip to content

Instantly share code, notes, and snippets.

AWSTemplateFormatVersion: "2010-09-09"
Description: "Static website hosting with S3 and CloudFront"
Parameters:
BucketName:
Type: String
Default: "a-proper-bucket-name"
Resources:
# Create the bucket to contain the website HTML
defmodule MyApp.TaskSupervisor do
use DynamicSupervisor
alias MyApp.Management
alias MyApp.WorkerStateStorage
def start_link(arg) do
DynamicSupervisor.start_link(__MODULE__, arg, name: __MODULE__)
end
defmodule MyApp.StarterWorker do
@moduledoc """
Start lost children
"""
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, [])
end
defmodule MyApp.TaskWorker do
use GenServer, restart: :transient
alias MyApp.Notify
alias MyApp.Management
alias MyApp.WorkerStateStorage
# client
def upsert_user_projects(user_id, project_ids) when is_list(project_ids) do
{:ok, time} = Ecto.Type.cast(:naive_datetime, Timex.now())
project_users =
project_ids
|> Enum.uniq()
|> Enum.map(fn project_id ->
%{
user_id: user_id,
project_id: project_id,
defmodule MyApp.Management.UserProject do
@moduledoc """
UserProject module
"""
use Ecto.Schema
import Ecto.Changeset
alias MyApp.Accounts.User
alias MyApp.Management.Project
...
def MyApp.Management.Project do
...
many_to_many(
:users,
User,
join_through: "user_project",
on_replace: :delete
)
...
def upsert_user_projects(user, project_ids) when is_list(project_ids) do
projects =
Project
|> where([project], project.id in ^project_ids)
|> Repo.all()
with {:ok, _struct} <-
user
|> User.changeset_update_projects(projects)
|> Repo.update() do
defmodule MyApp.Management.UserProject do
@moduledoc """
UserProject module
"""
use Ecto.Schema
import Ecto.Changeset
alias MyApp.Accounts.User
alias MyApp.Management.Project
@marinho10
marinho10 / default
Last active November 6, 2018 20:41
upstream phoenix {
server 127.0.0.1:4000 max_fails=5 fail_timeout=60s;
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name <server_name>;
location / {
# First attempt to serve request as file, then