Skip to content

Instantly share code, notes, and snippets.

View eahanson's full-sized avatar

Erik Hanson eahanson

View GitHub Profile
@eahanson
eahanson / phx_annotations.js
Created September 20, 2025 13:55
A bookmarklet that shows Phoenix component annotations
/**
* Toggles a visual overlay for Phoenix HEEx debug annotations.
*
* When enabled, this function adds a dashed outline to every HTML element that
* has a HEEx annotation comment. When the user hovers over an outlined element,
* a tooltip appears showing the formatted component and caller information.
*
* This version combines an annotation with its preceding '@caller' annotation
* into a single tooltip for clarity.
*
@eahanson
eahanson / test-names.txt
Last active May 15, 2024 18:37
test data: 5-letter person names
Alice
Billy
Cindy
David
Emily
Frank
Greta
Henry
Irene
James
@eahanson
eahanson / test-colors.txt
Last active May 14, 2024 14:31
test data: 5-letter color names
Azure
Brown
Coral
Denim
Ebony
Flame
Green
Hazel
Ivory
Jaune
@eahanson
eahanson / bookmarklet.js
Created August 23, 2023 17:39
bookmarklet that shows the value of the first "test-page" attribute it finds
javascript:(function()%7B(function()%20%7B%0A%20%20%20%20let%20elem%20%3D%20document.querySelector('%5Btest-page%5D')%3B%0A%20%20%20%20%0A%20%20%20%20if%20(elem%20%26%26%20elem.getAttribute('test-page'))%20%7B%0A%20%20%20%20%20%20%20%20let%20value%20%3D%20elem.getAttribute('test-page')%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20let%20div%20%3D%20document.createElement('div')%3B%0A%20%20%20%20%20%20%20%20let%20input%20%3D%20document.createElement('input')%3B%0A%20%20%20%20%20%20%20%20input.setAttribute('type'%2C%20'text')%3B%0A%20%20%20%20%20%20%20%20input.setAttribute('value'%2C%20value)%3B%0A%20%20%20%20%20%20%20%20input.setAttribute('size'%2C%2030)%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20div.style.position%20%3D%20'fixed'%3B%0A%20%20%20%20%20%20%20%20div.style.top%20%3D%20'0'%3B%0A%20%20%20%20%20%20%20%20div.style.left%20%3D%20'0'%3B%0A%20%20%20%20%20%20%20%20div.style.background%20%3D%20'rgb(255%2C%20233%2C%200)'%3B%0A%20%20%20%20%20%20%20%20div.style.padding%20%3D%20'10px'%3B%
@eahanson
eahanson / minified (create a bookmark with this value)
Last active May 23, 2023 02:39
Show "test-*" attributes on an HTML page
javascript:(function()%7Bjavascript%3A(function()%20%7B%20%20function%20showTestAttributes()%20%7B%20%20%20%20const%20elements%20%3D%20document.querySelectorAll('*')%3B%20%20elements.forEach(element%20%3D%3E%20%7B%20%20%20%20const%20attributes%20%3D%20Array.from(element.attributes)%3B%20%20%20%20const%20testAttributes%20%3D%20attributes.filter(attr%20%3D%3E%20attr.name.startsWith('test-'))%3B%20%20%20%20testAttributes.forEach(attr%20%3D%3E%20%7B%20%20%20%20%20%20const%20label%20%3D%20document.createElement('span')%3B%20%20%20%20%20%20label.style.cssText%20%3D%20%60%20%20%20%20%20%20%20%20background-color%3A%20rgba(255%2C%20233%2C%200%2C%200.3)%3B%20%20%20%20%20%20%20%20border%3A%201px%20solid%20rgb(0%2C%200%2C%200%2C%200.3)%3B%20%20%20%20%20%20%20%20color%3A%20black%3B%20%20%20%20%20%20%20%20font-family%3A%20monospace%3B%20%20%20%20%20%20%20%20font-size%3A%209px%3B%20%20%20%20%20%20%20%20font-weight%3A%20bold%3B%20%20%20%20%20%20%20%20left%3A%200px%3B%20%20%20%20%20%20%20%20padding%3A%202px%206px%3B%20%20%20%
#!/bin/bash
REPO_DIR=$1
SHA=$2
if [ -z "${REPO_DIR}" ] || [ -z "${SHA}" ]; then
echo "Steals a commit from another repo to this repo"
echo "USAGE: ${0} <source-repo-dir> <sha-to-steal>"
exit 1
fi
defmodule Dice do
def roll(number_of_dice, number_of_sides \\ nil) do
for _roll <- 1..number_of_dice do
number_of_sides = number_of_sides || sides()
1..number_of_sides |> Enum.random() |> color() |> IO.puts()
end
end
def color(text) do
IO.ANSI.color(32) <> to_string(text) <> IO.ANSI.reset()
@eahanson
eahanson / bookmarklet.js
Last active July 9, 2020 15:40
Bookmarklet that adds a short ID to each tracker story; use something like this to convert to bookmarklet: https://mrcoles.com/bookmarklet/
document.querySelectorAll(".shortStoryId").forEach(function(oldShortStoryId) {
oldShortStoryId.remove();
});
document.querySelectorAll(".story").forEach(function (story) {
const storyIdAttr = story.getAttribute("data-id");
const storyId = parseInt(storyIdAttr,10).toString(36);
const storyElement = document.createElement("span");
const front = storyId.slice(0, -3);
const back = storyId.slice(-3);
@eahanson
eahanson / Gemfile
Last active August 29, 2015 14:06
using rouge and redcarpet to display markdown
...
gem 'redcarpet'
gem 'rouge'
...
@eahanson
eahanson / gist:9691602
Created March 21, 2014 17:44
Get query params and add new query params to a URL
def query_param_value(url, query_param)
Addressable::URI.parse(url).query_values[query_param]
end
def add_query_params(url, query_params)
Addressable::URI.parse(url).tap do |parsed_url|
parsed_url.query_values = parsed_url.query_values.merge query_params
end.to_s
end