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
// get same day of the week in the last x years ago for specific date. | |
// Default is 1 year ago, and default date is today, takes account of leap year | |
function getPreviousYearSameDay(dateToStart = false, years = 1) { | |
const date = dateToStart ? new Date(dateToStart) : new Date(); | |
const lastYear = new Date(date.getFullYear() - years, date.getMonth(), date.getDate()); | |
const dayDiff = date.getDay() - lastYear.getDay(); | |
return new Date(lastYear.setDate(date.getDate() + dayDiff)); | |
} | |
console.log(getPreviousYearSameDay('2024-10-10', 1).toISOString()); // 2023-10-11T23:00:00.000Z |
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
def Jaccard_Similarity(doc1, doc2): | |
# List the unique words in a document | |
words_doc1 = set(doc1.lower().split()) | |
words_doc2 = set(doc2.lower().split()) | |
# Find the intersection of words list of doc1 & doc2 | |
intersection = words_doc1.intersection(words_doc2) | |
# Find the union of words list of doc1 & doc2 |
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
# google sheets app script to get file size in bytes from a url | |
function getSizes(theurl) { | |
const response = UrlFetchApp.fetch(theurl); | |
const blob = response.getBlob() | |
const size = blob.getBytes().length | |
return size | |
} |
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
// config | |
const sitemapFile = '/var/www/html/mastodon_sitemap.xml'; // path / name of the created sitemap | |
const mastodonServer = 'https://yourmastodon.domain'; // your mastodon server, no trailing slash | |
const numberofPosts = 10000; // number of posts to include in the sitemap | |
const pingGoogle = false; // true or false | |
const pingURL = 'enter_full_final_accessible_url'; // URL to ping Google with, if you're putting on differet domain, see cross-site sitemaps https://developers.google.com/search/docs/crawling-indexing/sitemaps/large-sitemaps#manage-sitemaps-for-multiple-sites | |
// end config | |
const fs = require('fs'); |
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
# before server {} block | |
# if you're not mapping $request_path already, you'll need to this next block | |
map $request_uri $request_path { | |
~(?<captured_path>[^?]*) $captured_path; | |
} | |
map $arg_resource $valid_mastodon { | |
# If you want any account at your domain to resolve to just one mastodon account, i.e [email protected], [email protected] |
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
/* | |
* a cloudflare worker to remove the script tag they inject into the head if you have a cloudflare app installed. | |
* WARNING: some apps may not work if you remove this script tag!!! But things like logflare that add no js of | |
* their own should be fine. | |
*/ | |
addEventListener('fetch', event => { | |
const request = event.request | |
event.respondWith(handleRequest(request)) | |
}); |
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 fixedEncodeURI(str) { | |
const prepURL = new URL(str); | |
const origin = prepURL.origin; | |
let raw = str; | |
let decoded = decodeURI(str); | |
while (raw !== decoded) { | |
decoded = decodeURI(decoded); | |
raw = decodeURI(raw); | |
} | |
justPath = decoded.replace(origin, ''); |
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
// require libs | |
// run npm install @google-cloud/bigquery | |
const { BigQuery } = require('@google-cloud/bigquery'); | |
const fs = require('fs'); | |
// BigQuery Config - see https://cloud.google.com/docs/authentication/production#create_service_account | |
const options = { | |
keyFilename: '{path_to_key_file}', | |
projectId: '{project_id}', | |
}; |
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 normEncoding(string) { | |
try { | |
return urlEncodeCaseCorrect(encodeURI(path).replace(/%25/g, '%')); | |
} catch (e) { | |
return string; | |
} | |
} | |
function urlEncodeCaseCorrect(string) { | |
return path.replace(/%[0-9a-fA-F]{2}/g, function(match) { |
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
// update existing robots tag if one is there | |
const oldRobots = document.querySelector("[name='robots']"); | |
if (oldRobots) { | |
oldRobots.content = "noindex"; | |
} else { | |
// add one if none existed | |
const newRobots = document.createElement('meta'); | |
newRobots.name = "robots"; | |
newRobots.content = "noindex"; | |
document.getElementsByTagName('head')[0].prepend(newRobots); |
NewerOlder