Skip to content

Instantly share code, notes, and snippets.

View srcrip's full-sized avatar
🔮
typescript is best script

Andrew Stewart srcrip

🔮
typescript is best script
View GitHub Profile
@srcrip
srcrip / quick-relative-dates.ts
Created February 24, 2022 04:58
Doing 'x hours ago' conversions quickly.
const units = [
['year', 31536000],
['month', 2592000],
['day', 86400],
['hour', 3600],
['minute', 60],
['second', 1]
]
const duration = (timeAgoInSeconds: number) => {
@srcrip
srcrip / error_html.ex
Created February 15, 2024 19:42
Custom Phoenix error pages
# goes in lib/your_app_web/controllers/error_html.ex
defmodule ExampleWeb.ErrorHTML do
use ExampleWeb, :html
def render("404.html" = template, assigns) do
assigns =
assigns
|> Map.merge(%{__changed__: %{}})
|> assign(:message, Phoenix.Controller.status_message_from_template(template))
import 'phoenix_html'
import { Socket } from 'phoenix'
import { LiveSocket } from 'phoenix_live_view'
const hooks = {}
// you can get this from the admin panel
const formId = '<insert here>'
const apiKey = '<insert here>'
const fetchOpts = {
@srcrip
srcrip / example.html.heex
Last active May 3, 2024 14:30
Some helper functions for making nested forms in LiveView
<.form for={@form} class="max-w-xs">
<NestedFormComponents.inputs_for_embeds
:let={embed_form}
parent_form={@form}
field={@form[:items]}
id={"#{@form[:items].id}_embeds"}
sort_param={:items_sort}
drop_param={:items_drop}
>
<div class="grow">
@srcrip
srcrip / tailwindForms.js
Created September 21, 2024 15:47
This is just a copy-and-paste of the Tailwind Forms plugin that you can actually edit/customize/maintain + JSDoc types.
// Tailwind plugin for forms.
// Basically: https://github.com/tailwindlabs/tailwindcss-forms/blob/main/src/index.js
// But with a few changes. And it's easier to maintain this way.
const svgToDataUri = require("mini-svg-data-uri")
const plugin = require("tailwindcss/plugin")
const defaultTheme = require("tailwindcss/defaultTheme")
const colors = require("tailwindcss/colors")
const [baseFontSize, { lineHeight: baseLineHeight }] =
defaultTheme.fontSize.base
const { spacing, borderWidth, borderRadius } = defaultTheme
@srcrip
srcrip / nvim.lua
Created April 19, 2025 13:45
Jump to Phoenix file annotations in html
-- Jump to Phoenix location annotations from html like:
-- <!-- <DemoWeb.CoreComponents.button> lib/demo_web/components/core_components.ex:543 (demo) -->
-- Assumes you have copied the annotation to your clipboard.
-- Just hit ctrl-c with the html comment selected in the inspector.
function PhoenixJumpFromClipboard()
-- Get clipboard content
local clipboard = vim.fn.getreg "+"
-- Pattern to match file path and line number
-- Looks for lib/path/file.ext:123 pattern