Content-Length: 184472 | pFad | https://gist.github.com/adactio

00 adactio’s gists · GitHub
Skip to content

Instantly share code, notes, and snippets.

View adactio's full-sized avatar

Jeremy Keith adactio

View GitHub Profile
@adactio
adactio / geocode.php
Created December 16, 2024 15:04
A PHP script that uses a third-party provider to get latitude, longitude, and zoom level (for use in embedded maps).
<?php
/*
Pass in a string: geocode("The Jolly Brewer, Brighton, East Sussex England")
The output is an array with keys for "latitude", "longitude", and "zoom".
*/
function geocode($location, $provider = "mapquest") {
$return = array();
@adactio
adactio / embedMap.js
Created December 16, 2024 12:11
embed-map is an HTML web component
class EmbedMap extends HTMLElement {
constructor () {
super();
}
loadScript(src, callback) {
let script = document.createElement('script');
script.src = src;
script.addEventListener('load', callback);
document.querySelector('head').appendChild(script);
}
<?php
/*
Pass in an array of data that includes the text of the post and an access token e.g.
postToBluesky(array(
'text' => 'Hello World',
'accessToken' => getBlueskyToken()
));
Here's the gist for getting getBlueskyToken():
https://gist.github.com/adactio/1a850920a0554a49f36daf79d776a440
@adactio
adactio / getBlueskyToken.php
Last active November 27, 2024 11:42
A PHP function that returns the token you need to post something to Bluesky
<?php
/*
Use this function whenever you need a token from Bluesky e.g.
$my_token = getBlueskyToken();
*/
function getBlueskyToken() {
$url = "https://bsky.social/xrpc/com.atproto.server.createSession";
@adactio
adactio / redirect.php
Last active January 2, 2024 23:24
A proxy that tries to redirect bad links to the internet archive.
<?php
// Check that the request is coming from my site.
if (!isset($_SERVER['HTTP_REFERER']) || !stristr(strtolower($_SERVER['HTTP_REFERER']), strtolower($_SERVER['SERVER_NAME']))) {
http_response_code(403);
exit;
}
// There has to be a URL provided in the query string.
if (!isset($_GET['url'])) {
@adactio
adactio / redirectLinks.js
Last active November 20, 2023 18:11
Intercept clicks on external links and pass them to a redirector.
@adactio
adactio / autoLinkMastodonUsernames.php
Created October 30, 2023 13:11
A regular expression to convert @@ usernames into hyperlinks
<?php
/* Pass a string of text into the function to convert @@ usernames. */
function autoLinkMastodonUsernames($string) {
return preg_replace(
'/@?\b([A-Za-zŽžÀ-ÿ0-9._%+-]+)@([A-Za-zŽžÀ-ÿ0-9.-]+\.[A-Za-zŽžÀ-ÿ]{2,})\b/i',
'<a href="https://$2/@$1">$0</a>',
$string
@adactio
adactio / updateDateTimes.js
Last active September 11, 2023 05:10
Periodically update the text of `datetime` elements with the relative time elapsed.
(function (win, doc) {
'use strict';
if (!doc.querySelectorAll || !win.Intl || !win.Intl.RelativeTimeFormat) {
// doesn't cut the mustard.
return;
}
var rtf = new Intl.RelativeTimeFormat('en', {
localeMatcher: 'best fit',
numeric: 'always',
style: 'long'
@adactio
adactio / postToMastodon.php
Last active December 22, 2022 16:27
A PHP function that posts an update to Mastodon
<?php
/*
Pass in an array of data with keys for `status`
e.g.
postToMastodon(array(
'status' => 'Hello, world!'
));
Include `reply_url` if you're responding to a post
@adactio
adactio / previewImageUploads.js
Created May 12, 2022 13:33
Show inline previews of images that are going to be uploaded.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win,doc) {
'use strict';
if (!win.FileReader || !win.addEventListener || !doc.querySelectorAll) {
// doesn't cut the mustard.
return;
}
doc.querySelectorAll('input[type="file"][accept="image/*"]').forEach( function (fileInput) {








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://gist.github.com/adactio

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy