Skip to content

Instantly share code, notes, and snippets.

View bnchrch's full-sized avatar
🏡
Working from wherever makes me happy.

Ben Church bnchrch

🏡
Working from wherever makes me happy.
View GitHub Profile

Keybase proof

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:

# ...
# 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]
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"}
@bnchrch
bnchrch / ViewController.swift
Created July 20, 2018 20:24
Sum and render mindful minutes
// 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)
}
@bnchrch
bnchrch / main.go
Created July 7, 2018 17:57
Serve a reverse proxy
// 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