Skip to content

Instantly share code, notes, and snippets.

Avatar
🤡
warning: code maybe funnier than it appears.

Josh Chernoff joshchernoff

🤡
warning: code maybe funnier than it appears.
View GitHub Profile
@joshchernoff
joshchernoff / blog.ex
Last active May 7, 2020
How do I optimize LiveView while using pagination?
View blog.ex
# lib/MyApp/blog.ex
defmodule MyApp.Blog do
import Ecto.Query, warn: false
alias MyApp.Repo
alias __MODULE__.{Post}
def list_posts(params, user) do
Post
@joshchernoff
joshchernoff / index.ex
Last active May 7, 2020
Add pagination to your Phoenix LiveView project with Dissolver and live_patch https://github.com/MorphicPro/dissolver
View index.ex
# lib/my_app_web/live/post_live/index.ex
defmodule MyAppWeb.PostLive.Index do
use MyAppWeb, :live_view
alias MyApp.Blog
@impl true
def mount(_params, _session, socket) do
{:ok, socket}
@joshchernoff
joshchernoff / blog.ex
Last active May 4, 2020
LiveView Post Show
View blog.ex
# lib/morphic_pro/blog.ex
defmodule MorphicPro.Blog do
...
def get_post!(slug, current_user, options \\ []) do
preload = Keyword.get(options, :preload, [])
Post
|> Repo.by_slug(slug)
View keybase.md

Keybase proof

I hereby claim:

  • I am joshchernoff on github.
  • I am morphicpro (https://keybase.io/morphicpro) on keybase.
  • I have a public key ASC1HTXsG6Lo4_QAdZnmdF0z3K_WLjOuFzuhbSweHpCKFgo

To claim this, I am signing this object:

@joshchernoff
joshchernoff / nginx configure
Last active Mar 21, 2020
Optimal compile for nginx on ubuntu for elixir apps
View nginx configure
sudo apt update && \
sudo apt install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev\
libssl-dev libxml2 libxml2-dev libxslt-dev libgd-dev geoip-database-extra
sudo ./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
View Custom phoenix form input helper
defmodule MyAppWeb.InputHelper do
use Phoenix.HTML
def input(form, field, opts \\ []) do
type = Phoenix.HTML.Form.input_type(form, field)
wrapper_classes = Keyword.get_values(opts, :wrapper_class) ++ ["row", "form-group"]
inputs_classes = Keyword.get_values(opts, :input_class) ++ ["form-control"]
if form.errors[field], do: inputs_classes = inputs_classes ++ ["form-control-danger"]
You can’t perform that action at this time.