Skip to content

Instantly share code, notes, and snippets.

View agamm's full-sized avatar
🍪
Cookie: cookies=∞;\r\n

Agam More agamm

🍪
Cookie: cookies=∞;\r\n
View GitHub Profile
@agamm
agamm / getVisibleElements.js
Last active October 13, 2022 22:08
Get only visible text elements from HTML of a page.
// From the creator of unzip.dev
const texts = document.querySelectorAll(
"p, span, a, h1, h2, h3, h4, h5, h6, input, button, pre"
);
let visible = [];
texts.forEach((e) => {
var style = window.getComputedStyle(e);
if (style.display !== "none" && style.visibility !== "hidden") {
visible.push(e);
@agamm
agamm / testing.helper.ts
Last active October 22, 2022 22:02
Table tests with Jest (including exceptions)
// If you ever so fancy, you might want to check: unzip.dev
export const tableTest = (
test: jest.It,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cases: any[][],
testFn: CallableFunction
) => {
test.each(cases)(`${testFn.name}(%s) should be %s`, async (input, output) => {
const asyncFn = testFn.constructor.name == 'AsyncFunction';
@agamm
agamm / fixLinks.js
Last active October 13, 2022 21:58
Fix Ghost newsletter links and add ?ref= to referenced links
@agamm
agamm / settings.py
Created December 1, 2022 18:03
Django settings for postgres from URI
import urllib
# ...
DB_URL = config('DATABASE_URL') # Get from your config
db_props = urllib.parse.urlparse(DB_URL)
db_name = db_props.path
db_user = db_props.username
db_password = db_props.password
db_host = db_props.hostname
db_port = db_props.port
@agamm
agamm / domains.json
Created September 23, 2023 11:15
Match urls to Alexa 1M top websites
["yourdomain.com", "your2nddomain.com"...]
@agamm
agamm / fixUrls.js
Created February 1, 2024 07:53
Ghost Editor Link Fixer and ?ref= adder
/*
This script helps fix links that have a prefix whitespace (sometimes when copying from google).
Also it allows to add a ?ref=yoursite to all links in the newsletter issue.
Worked with the latest ghost version up to now (Feb 2024)
*/
const GhostAdminAPI = require("@tryghost/admin-api");
const path = require("path");
import fs from "fs";
import fse from "fs-extra";
import path from "path";
import { promisify } from "util";
import { exec } from "child_process";
const execAsync = promisify(exec);
function chunkArray(array, chunkSize) {
const chunks = [];