I hereby claim:
- I am bechurch on github.
- I am bnchrch (https://keybase.io/bnchrch) on keybase.
- I have a public key ASDL7eb9NWOfPhQ90p060zllqwEONkIYRgFtaRLIviuabwo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# ... | |
# Configure your database | |
config :shorten_api, ShortenApi.Repo, | |
adapter: EctoMnesia.Adapter | |
config :ecto_mnesia, | |
host: {:system, :atom, "MNESIA_HOST", Kernel.node()}, | |
storage_type: {:system, :atom, "MNESIA_STORAGE_TYPE", :disc_copies} | |
config :mnesia, |
defmodule ShortenApiWeb.Router do | |
use ShortenApiWeb, :router | |
pipeline :api do | |
plug :accepts, ["json"] | |
end | |
scope "/api", ShortenApiWeb do | |
pipe_through :api | |
resources "/links", LinkController, except: [:edit] |
# ... | |
def get_and_redirect(conn, %{"id" => id}) do | |
url = id | |
|> Links.get_link!() | |
|> Map.get(:url) | |
redirect(conn, external: url) | |
end | |
# ... |
defmodule ShortenApi.Repo.Migrations.CreateLinks do | |
use Ecto.Migration | |
def change do | |
create table(:links, primary_key: false) do | |
add :hash, :string, primary_key: true | |
add :url, :string | |
timestamps() | |
end |
defmodule ShortenApi.Links.Link do | |
use Ecto.Schema | |
import Ecto.Changeset | |
alias ShortenApi.Ecto.HashId | |
@primary_key {:hash, HashId, [autogenerate: true]} | |
@derive {Phoenix.Param, key: :hash} | |
schema "links" do | |
field :url, :string |
defmodule ShortenApi.Ecto.HashId do | |
@behaviour Ecto.Type | |
@hash_id_length 8 | |
# ======================= # | |
# Ecto Specific Callbacks # | |
# ======================= # | |
@doc "Called when creating an Ecto.Changeset" | |
@spec cast(any) :: Map.t | |
def cast(value), do: hash_id_format(value) |
# ... | |
defp deps do | |
[ | |
{:phoenix, "~> 1.3.2"}, | |
{:phoenix_pubsub, "~> 1.0"}, | |
{:phoenix_ecto, "~> 3.2"}, | |
{:postgrex, ">= 0.0.0"}, | |
{:gettext, "~> 0.11"}, | |
{:cowboy, "~> 1.0"}, | |
{:ecto_mnesia, "~> 0.9.1"} |
// Sum the meditation time | |
func updateMeditationTime(query: HKSampleQuery, results: [HKSample]?, error: Error?) { | |
if error != nil {return} | |
let totalMeditationTime = results?.map(calculateTotalTime).reduce(0, { $0 + $1 }) ?? 0 | |
print("\n Total: \(totalMeditationTime)") | |
renderMeditationMinuteText(totalMeditationSeconds: totalMeditationTime) | |
} |
// Serve a reverse proxy for a given url | |
func serveReverseProxy(target string, res http.ResponseWriter, req *http.Request) { | |
// parse the url | |
url, _ := url.Parse(target) | |
// create the reverse proxy | |
proxy := httputil.NewSingleHostReverseProxy(url) | |
// Update the headers to allow for SSL redirection | |
req.URL.Host = url.Host |