Skip to content

Instantly share code, notes, and snippets.

View joshchernoff's full-sized avatar
💀
For your ego

Josh Чернов joshchernoff

💀
For your ego
View GitHub Profile
@joshchernoff
joshchernoff / app.js
Last active May 10, 2022 19:41
MinIO uploader for LiveView Uploader
let Uploaders = {}
Uploaders.S3 = function(entries, onViewError){
entries.forEach(entry => {
let {url, full_string} = entry.meta
console.debug(entry.file)
var blob = new Blob([entry.file], {type: entry.file.type});
let xhr = new XMLHttpRequest()
onViewError(() => xhr.abort())

Keybase proof

I hereby claim:

  • I am joshchernoff on github.
  • I am morphicpro (https://keybase.io/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
joshchernoff / blog.ex
Last active May 7, 2020 18:23
How do I optimize LiveView while using pagination?
# 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 September 26, 2021 04:55
Add pagination to your Phoenix LiveView project with Dissolver and live_patch https://github.com/MorphicPro/dissolver
# 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 20:25
LiveView Post Show
# 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)
@joshchernoff
joshchernoff / nginx configure
Last active March 21, 2020 01:07
Optimal compile for nginx on ubuntu for elixir apps
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 \
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"]