Skip to content

Instantly share code, notes, and snippets.

View mplatts's full-sized avatar

Matt Platts mplatts

View GitHub Profile
@mplatts
mplatts / 0firebase_functions_cheatsheet.js
Last active October 31, 2023 22:15
Firebase functions cheatsheet
// Core
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const db = admin.database();
admin.auth().createUser({
uid: uid,
displayName: displayName,
photoURL: photoURL
@mplatts
mplatts / command_line.sh
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
# DATABASE
mix ecto.gen.migration add_weather_table
mix ecto.migrate
@mplatts
mplatts / data.json
Created August 13, 2023 23:38
Fake Data
[{"timestamp":"2023-07-10T06:52:47.127Z","identity":"Secrets","location":"Excel","entity":"user","id":"8e4dc40c-04bb-4057-b8ca-2cc278b481f9","descriptor":"email"},{"timestamp":"2023-05-27T00:56:20.647Z","identity":"Health","location":"BigQuery","entity":"bank_account","id":"dd076f4e-f778-4af2-857b-867b4a07940f","descriptor":"address"},{"timestamp":"2023-05-24T20:26:24.610Z","identity":"Health","location":"BigQuery","entity":"purchase","id":"aca763b8-6d57-486b-a336-03c9b9fa5853","descriptor":"medications"},{"timestamp":"2023-07-29T06:09:34.004Z","identity":"PII","location":"Excel","entity":"prescription","id":"726279b7-841a-4639-9056-ef5857e013af","descriptor":"medications"},{"timestamp":"2023-08-12T15:25:29.609Z","identity":"PII","location":"Rails","entity":"user","id":"e79ec197-0173-4992-8b9b-b6cb34b52c4d","descriptor":"email"},{"timestamp":"2023-07-10T21:19:33.603Z","identity":"PII","location":"BigQuery","entity":"purchase","id":"e48c890a-c6af-4555-88db-052a33bfd133","descriptor":"email"},{"timestamp":"2023
@mplatts
mplatts / data_table.ex
Created March 2, 2023 05:39
data_table_streams
defmodule PetalFramework.Components.DataTable do
@moduledoc """
Render your data with ease. Uses Flop under the hood: https://github.com/woylie/flop
## Example
# In a Live View
defmodule PetalProWeb.AdminJobsLive do
use PetalProWeb, :live_view
def mount(_params, _session, socket) do
@mplatts
mplatts / button.html
Last active July 25, 2022 05:09
Combo box HEEX + Alpine JS
<button
@click.prevent="openDocs()"
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">
<svg
class="w-5 h-5"
viewbox="0 0 21 21"
fill="none"
xmlns="http://www.w3.org/2000/svg"
@mplatts
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())}
end
@mplatts
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
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>
</div>
<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)