Skip to content

Instantly share code, notes, and snippets.

View m3ta4a's full-sized avatar

Jake Van Alstyne m3ta4a

View GitHub Profile

Keybase proof

I hereby claim:

  • I am m3ta4a on github.
  • I am eggdevil (https://keybase.io/eggdevil) on keybase.
  • I have a public key whose fingerprint is 9CDA D1CA 92D7 A685 4E01 E516 FE2B 3B0B F337 B568

To claim this, I am signing this object:

@m3ta4a
m3ta4a / hosts
Last active July 19, 2020 21:25
0.0.0.0 ethicalads.io
0.0.0.0 server.ethicalads.io
defp deps do
[
{:phoenix, "~> 1.4.2"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 4.0"},
{:ecto_sql, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:gettext, "~> 0.11"},
def application do
[
mod: {AddressBook.Application, []},
extra_applications: [:logger, :runtime_tools, :timex]
]
end
defmodule AddressBook.People.Person do
use Ecto.Schema
use Timex
import Ecto.Changeset
def changeset(person, attrs) do
person
|> cast(attrs, [:name, :age, :birthday, :address])
|> validate_required([:name, :age, :birthday, :address])
end
end
scope "/", AddressBookWeb do
pipe_through :browser
get "/", PageController, :index
resources "/people", PersonController
end
# Configure your database
config :address_book, AddressBook.Repo,
 username: "postgres",
 password: "postgres",
 database: "address_book_dev",
 hostname: "localhost",
 pool_size: 10
<%= label f, :age %>
<%= number_input f, :age %>
<%= error_tag f, :age %>
@m3ta4a
m3ta4a / person.ex
Last active March 29, 2019 17:10
Person.ex changeset
def changeset(person, attrs) do
attrs = if attrs["birthday"] do
bday = attrs["birthday"]
{year, _} = Integer.parse(bday["year"])
{month, _} = Integer.parse(bday["month"])
{day, _} = Integer.parse(bday["day"])
case Timex.parse("#{year}/#{month}/#{day}", "{YYYY}/{M}/{D}") do
{:ok, date} ->
age = Timex.diff(Timex.now, date, :years)
Map.put(attrs, "age", age)