Skip to content

Instantly share code, notes, and snippets.

View GreenFootballs's full-sized avatar

Charles Johnson GreenFootballs

View GitHub Profile
@GreenFootballs
GreenFootballs / bluesky-embed.js
Last active May 23, 2024 18:13
Render Bluesky embedded posts dynamically, with callback when complete
/**
* bluesky-embed.js
*
* @author Charles Johnson
* @url https://github.com/GreenFootballs
*
* Adds an object named "_bluesky" to the window element, with an "embed" method.
*
* Runs automatically at window.onload, searches the page for blockquotes with a
* "data-bluesky-uri" attribute, converts them to iframes, and resizes them to fit the content.
@GreenFootballs
GreenFootballs / mastodon-embed.js
Last active June 13, 2023 18:37
Revised Mastodon embed script, handles dynamically added oembed iframes
/**
* Revised by Charles Johnson - https://github.com/GreenFootballs
*
* Runs automatically at window.onload(), searches document for iframes with a class of "mastodon-embed"
* and resizes them to fit the content, using window.postMessage() to get the content height from the
* embedded page.
*
* Adds an object named "_mastodonTools" to the window element, with an "embed" method.
*
* To resize dynamically added Mastodon iframes, call "_mastodonTools.embed(container, callback)"
@GreenFootballs
GreenFootballs / amazon_regex.md
Last active August 31, 2022 11:12
A PHP regular expression to match Amazon links and extract the ASIN identifier
~
    (?:(smile\.|www\.))?    # optionally starts with smile. or www.
    ama?zo?n\.              # also allow shortened amzn.com URLs
    (?:
        com                 # match all Amazon domains
        |
        ca
        |
        co\.uk
@GreenFootballs
GreenFootballs / as_addslashes.md
Last active April 1, 2017 17:41
An Applescript subroutine that mimics PHP's addslashes() to escape single/double quotes
on addslashes(s)
	return (do shell script "sed 's/[\"\\\\'\\'']/\\\\&/g' <<<" & quoted form of s)
end addslashes