Given this kind of relationship from
GET /projects/1
const response = {
id: 1,
name: 'Normalized Redux',
type: 'project',
task_lists: [
Given this kind of relationship from
GET /projects/1
const response = {
id: 1,
name: 'Normalized Redux',
type: 'project',
task_lists: [
# router_factory.ex | |
defmodule App.RouterFactory do | |
use Plug.Builder | |
def init(opts) do | |
opts | |
end | |
def call(conn, opts) do | |
router = make(conn.req_headers) |
defmodule Turbolinks do | |
@moduledoc """ | |
in `web.ex` | |
replace `use Phoenix.Controller` with `use Turbolinks` | |
in `router.ex` add a the plug | |
plug Turbolinks | |
""" | |
use Plug.Builder |
I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.
I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.
Chrome 51 has some pretty wild behaviour related to console.log
in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.
Ecto.Repo by default doesn't allow overrides. So when you need to compose functions but maintain an API parity with the Ecto.Repo. You'd need to compose the functions in another module and things can get messy really fast that way.
Can't invoke super
== Compilation error on file lib/app/repo.ex ==
** (CompileError) lib/app/repo.ex:6: no super defined for all/2 in module App.Repo. Overridable functions available are:
iex> alias Data.Post
iex> Post |> Post.by_status(:published) |> Repo.all()
iex> Post |> Post.by_status([:draft, :published]) |> Repo.all()
defmodule Blog.Attachment do | |
use Blog, :schema | |
@primary_key {:id, :binary_id, autogenerate: true} | |
@storage_path "attachments" | |
schema "attachments" do | |
field :file, :any, virtual: true | |
belongs_to :post, Post |
initial = %{sunday: 0, monday: 0, tuesday: 0, wednesday: 0, thursday: 0, friday: 0, saturday: 0} | |
from(o in Order, | |
where: o.inserted_at > fragment("DATE_TRUNC('week', CURRENT_TIMESTAMP)"), | |
group_by: fragment("EXTRACT(DOW FROM ?)", o.inserted_at), | |
order_by: fragment("EXTRACT(DOW FROM ?)", o.inserted_at), | |
select: {fragment("EXTRACT(DOW FROM ?)", o.inserted_at), count(o.id)} | |
) | |
|> Repo.all() | |
|> Enum.reduce(initial, fn |
defmodule Shopify.Cache do | |
use Maxwell.Middleware | |
alias :timer, as: Timer | |
@ttl Timer.minutes(5) | |
def call(conn, next, opts), do: get!(conn, fn _ -> super(conn, next, opts) end) | |
def get!(key, fallback \\ nil) do |