Skip to content

Instantly share code, notes, and snippets.

View mplatts's full-sized avatar

Matt Platts mplatts

View GitHub Profile
mplatts / data.json
Created August 13, 2023 23:38
Fake Data
mplatts / data_table.ex
Created March 2, 2023 05:39
defmodule PetalFramework.Components.DataTable do
@moduledoc """
Render your data with ease. Uses Flop under the hood:
## Example
# In a Live View
defmodule PetalProWeb.AdminJobsLive do
use PetalProWeb, :live_view
def mount(_params, _session, socket) do
mplatts / button.html
Last active July 25, 2022 05:09
Combo box HEEX + Alpine JS
class="items-center hidden w-full px-4 mr-auto border rounded-lg dark:border-gray-600 dark:bg-gray-900 dark:hover:bg-gray-800/30 bg-slate-100 hover:bg-slate-50 md:flex group"
<div class="mr-2 text-gray-400">
class="w-5 h-5"
viewbox="0 0 21 21"
mplatts / checkbox_live.ex
Created June 14, 2022 22:39
Petal Components Checkbox Group Example
defmodule PetalBoilerplateWeb.CheckboxLive do
use PetalBoilerplateWeb, :live_view
alias PetalBoilerplateWeb.Components.Layouts.SidebarLayout
alias Ecto.Changeset
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, changeset: build_suggestion_changeset())}
mplatts / register_live_test.ex
Created November 25, 2021 21:19
LiveView Testing
defmodule PetalProWeb.RegisterLiveTest do
use PetalProWeb.ConnCase, async: true
alias PetalProWeb.RegisterLive
import Phoenix.LiveViewTest
test "can register an account", %{conn: conn} do
{:ok, view, html} = live(conn, Routes.live_path(conn, RegisterLive))
assert html =~ "Register"
mplatts / register_live.ex
Created November 25, 2021 21:18
Elixir Phoenix LiveView
defmodule PetalProWeb.RegisterLive do
use PetalProWeb, :live_view
alias PetalPro.{Accounts, Repo}
alias PetalPro.Accounts.{User}
def mount(params, _session, socket) do
socket =
assign(socket, %{
user_return_to: Map.get(params, "user_return_to", nil),
error_message: nil,
<div class="<%= container_css() %> py-10">
<div class="md:grid md:grid-cols-3 md:gap-6">
<div class="md:col-span-1">
<div class="px-4 sm:px-0">
<h3 class="text-lg font-medium leading-6 text-gray-900">Change your name</h3>
<div class="mt-5 md:mt-0 md:col-span-2">
<%= form_for @name_changeset, Routes.user_settings_path(@conn, :update_name), fn f -> %>
<div class="shadow sm:rounded-md sm:overflow-hidden">
defmodule AppWeb.PageLive do
use AppWeb, :live_view
alias App.Posts
alias App.Posts.Post
alias App.Votes
@impl true
def mount(_params, session, socket) do
socket = maybe_assign_user(session, socket)
mplatts / gist:a274e699b88538df4b63fb66c46af663
Created May 5, 2020 20:47 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
mplatts /
Last active October 5, 2023 08:46
Elixir Phoenix Cheatsheet
mix help
iex -S mix phx.server # like rails c
h Enum => shows help for Enum
Dossy.Accounts.__info__(:functions) => will list functions in this module
mix phx.routes
mix ecto.gen.migration add_weather_table
mix ecto.migrate