mix phx.new --binary-id budgie
# add docker-compose.yml below
mix setup
mix phx.gen.auth Accounts User users --hashing-lib argon2
Edit mix.ex
defp deps do
~r/^[A-Za-z0-9]+$/ | |
~r/^[A-Za-z0-9]{6}$/ |
defmodule UrlshortenerWeb.UrlLiveTest do | |
use UrlshortenerWeb.ConnCase, async: true | |
import Phoenix.LiveViewTest | |
describe "URL live tests" do | |
test "we can render the view", %{conn: conn} do | |
{:ok, _lv, html} = live(conn, ~p"/") | |
# open_browser(lv) |
mix phx.new --binary-id budgie
# add docker-compose.yml below
mix setup
mix phx.gen.auth Accounts User users --hashing-lib argon2
Edit mix.ex
defp deps do
defmodule MyApp.Guards do | |
defguard is_uuid(value) | |
when is_binary(value) and byte_size(value) == 36 and | |
binary_part(value, 1, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and | |
binary_part(value, 2, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and | |
binary_part(value, 3, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and | |
binary_part(value, 4, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and | |
binary_part(value, 5, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and | |
binary_part(value, 6, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and | |
binary_part(value, 7, 1) in ~w|0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F| and |
git config diff.sopsdiffer.textconv "sops --decrypt --config /dev/null" |
-- v5 | |
----------------------------------------------------------- basic instance info | |
-- show db version | |
SELECT version(); | |
-- uptime | |
SELECT pg_postmaster_start_time(); | |
-- show connections |
{ | |
"data": {"values": | |
[ | |
{"_submitted_by": "dalli", | |
"INTRO_DISTRICT": [ | |
"Afgooye" | |
], | |
"count": 1 | |
}, | |
{"_submitted_by": "dalli", |
Generators are implemented with syntax very similar to functions, but instead of returning values, a yield statement is executed to indicate each element in the series
Consider the goal of computing all factors of a positive integer. A traditional function might return a list contating all factors, implemeted as follows:
def factors(n): # traditional function that computes factors
results = [] # store factors in a new list
for k in range(1, n+1):
if n % k == 0: # divides evenly, thus k is a factor
results.append(k) # add k to the list of factors