This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<.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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const units = [ | |
['year', 31536000], | |
['month', 2592000], | |
['day', 86400], | |
['hour', 3600], | |
['minute', 60], | |
['second', 1] | |
] | |
const duration = (timeAgoInSeconds: number) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
env: { | |
browser: true, | |
es2022: true | |
}, | |
extends: [ | |
'standard', | |
'eslint:recommended' | |
], | |
parser: '@typescript-eslint/parser', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript (src) { | |
return new Promise((resolve, reject) => { | |
const script = document.createElement('script') | |
script.type = 'text/javascript' | |
script.src = src | |
script.addEventListener('load', () => resolve(script), false) | |
script.addEventListener('error', () => reject(script), false) | |
document.body.appendChild(script) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext, useState, useContext } from 'react' | |
import update from 'immutability-helper' | |
import './App.css' | |
const CounterContext = createContext() | |
const CounterProvider = ({ children }) => { | |
const [state, setState] = useState({ | |
resources: [ | |
{ name: 'stone', amount: 0 }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import browser from 'webextension-polyfill' | |
// Flatten a tree with 'children' properties recursively | |
const flattenTree = data => { | |
return data.reduce((r, { children, ...rest }) => { | |
if (rest.url) r.push(rest) | |
if (children) r.push(...flattenTree(children)) | |
return r | |
}, []) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts an array like: | |
# ["M", nil, "G", nil, "G"] | |
# to: | |
# {0=>"M", 1=>nil, 2=>"G", 3=>nil, 4=>"G"} | |
def to_indexed_hash(arr) | |
arr.each_with_object({}).with_index { |(el, acc), index| acc[index] = el } | |
end | |
# Is this pointless? Probably. I thought it was interesting though. |
NewerOlder