Skip to content

Instantly share code, notes, and snippets.

warning: code maybe funnier than it appears.

Josh Чернов joshchernoff

warning: code maybe funnier than it appears.
View GitHub Profile

Keybase proof

I hereby claim:

  • I am joshchernoff on github.
  • I am morphicpro ( on keybase.
  • I have a public key whose fingerprint is 951E F8BE DBF3 1583 B828 98B1 1770 A0DD 6A70 756C

To claim this, I am signing this object:

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
joshchernoff / index.ex
Last active Sep 26, 2021
Add pagination to your Phoenix LiveView project with Dissolver and live_patch
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 / 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, [])
|> Repo.by_slug(slug)
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"]