Skip to content

Instantly share code, notes, and snippets.

defmodule Votio.TopicChannel do
use Votio.Web, :channel
use Guardian.Channel
def join("topics:lobby", %{claims: claim, resource: resource}, socket) do
{:ok, %{ message: "Joined"}, socket}
end
def join("topics:lobby", _, socket) do
{:error, %{error: "authentication required"}}
defmodule Votio.TopicChannelTest do
use Votio.ChannelCase
alias Votio.TopicChannel
import Votio.Factory
setup do
user = create(:user)
{:ok, jwt, full_claims} = Guardian.encode_and_sign(user)
{:ok, _, socket} =
defmodule Votio.Topic do
use Votio.Web, :model
schema "topics" do
field :title, :string
field :categories, :map
field :voted_by, {:array, :id}
timestamps
defmodule Votio.TopicChannelTest do
use Votio.ChannelCase
alias Votio.TopicChannel
alias Votio.Topic
alias Votio.TopicView
import Votio.Factory
@valid_attrs %{"message" => %{"categories" => %{"yep" => 0, "nope" => 0}, "title" => "some content"}}
@updated_vote update_in @valid_attrs, ["message", "categories", "yep"], &(&1 + 1)
defmodule Votio.TopicChannelTest do
use Votio.ChannelCase
alias Votio.TopicChannel
alias Votio.Topic
alias Votio.TopicView
import Votio.Factory
@valid_attrs %{"message" => %{"categories" => %{"yep" => 0, "nope" => 0}, "title" => "some content"}}
@changeset_data %{"categories" => %{"yep" => 0, "nope" => 0}, "title" => "some content"}
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
defmodule Roman do
@doc """
Convert the number to a roman number.
"""
@ones %{"0" => "", "1" => "I", "2" => "II", "3" => "III", "4" => "IV", "5" => "V", "6" => "VI", "7" => "VII", "8" => "VIII", "9" => "IX"}
@tens %{"0" => "", "1" => "X", "2" => "XX", "3" => "XXX", "4" => "XL", "5" => "L", "6" => "LX", "7" => "LXX", "8" => "LXXX", "9" => "XC"}
@hundos %{"0" => "", "1" => "C", "2" => "CC", "3" => "CCC", "4" => "CD", "5" => "D", "6" => "DC", "7" => "DCC", "8" => "DCCC", "9" => "CM"}
@kilos %{"0" => "", "1" => "M", "2" => "MM", "3" => "MMM"}
@spec numerals(pos_integer) :: String.t
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
.idea
.env
defmodule PrimeFactors do
@doc """
Compute the prime factors for 'number'.
The prime factors are prime numbers that when multiplied give the desired
number.
The prime factors of 'number' will be ordered lowest to highest.
"""
defmodule Luhn do
@spec is_luhn?(number()) :: boolean()
def is_luhn?(number) do
number |>
Integer.digits |>
Enum.reverse |>
sort_and_sum_numbers |>
verify?
end