Skip to content

Instantly share code, notes, and snippets.

View Dan-Q's full-sized avatar
🦆

Dan Q Dan-Q

🦆
View GitHub Profile
@Dan-Q
Dan-Q / jigidi-helper.js
Last active April 4, 2024 20:31
Experimental under-development code to streamline Jigidi solving.
window.jColors = ['red', 'blue', 'brown', 'orange', 'yellow', 'pink', 'lightblue', 'lightgreen', 'lightgray'];
window.lColors = ['white', 'black', 'purple', 'darkgray', '#009'];
window.lWidths = [5, 10, 20];
window.jCols = parseInt(document.getElementById('info-creator').innerText.match(/(\d+)×/)[1]);
window.jC = 0;
CanvasRenderingContext2D.prototype.putImageData = function(imageData, dx, dy){
const col = window.jC % window.jCols;
const row = Math.floor(window.jC / window.jCols);
this.fillStyle = window.jColors[col % window.jColors.length];
this.fillRect(-1000,-1000,2000,2000);
@Dan-Q
Dan-Q / geocaching-extent.php
Created April 3, 2024 15:44
Draws the smallest possible convex polygon that surrounds a set of successful geocaching finds/geohashpoint expeditions. See: https://danq.me/geo-limits
<?php
/**
* Given an array of points, returns the convex hull over those points.
*/
function convex_hull_over( array $points ): array {
$cross = function($o, $a, $b) {
return ($a[0] - $o[0]) * ($b[1] - $o[1]) - ($a[1] - $o[1]) * ($b[0] - $o[0]);
};
$pointCount = count($points);
@Dan-Q
Dan-Q / list-detected-woocom-components.user.js
Created April 2, 2024 21:04
Userscript to report WooCom components detected on each visited page, by logging to console.log
// ==UserScript==
// @name WooCom Component Enumerator
// @namespace woo.com.danq.me
// @match https://woo.com/*
// @match https://woocommerce.test/*
// @grant none
// @version 1.0
// @author -
// @description Lists detected WooCom PHP/React components in the console.log as-you-browse.
// ==/UserScript==
SITE = 'https://danq.me/';
NEW_SIZE = 234;
me = document.querySelector(`a[href="${SITE}"]`).closest('li');
before = me.querySelector('.before');
after = me.querySelector('.after');
i = parseInt(after.innerText);
ticker = function(){
i += (i > NEW_SIZE ? -1 : 1);
before.style.setProperty('--data-size', i);
@Dan-Q
Dan-Q / bbc-news-rss-filter-sport-out.rb
Last active March 10, 2024 07:44
Improve the BBC News RSS feed by (a) filtering out sport, iplayer links, and BBC sounds links; and (b) stripping the anchor (#0, #1, #2 etc.) off <guid>s so "republished to front page" stories don't re-appear in your feed reader
#!/usr/bin/env ruby
require 'bundler/inline'
# # Sample crontab:
# # Every twenty minutes, run the script and log the results
# */20 * * * * ~/bbc-news-rss-filter-sport-out.rb > ~/bbc-news-rss-filter-sport-out.log 2>>&1
# Dependencies:
# * open-uri - load remote URL content easily
# * nokogiri - parse/filter XML
@Dan-Q
Dan-Q / footnotes-for-wordpress.php
Created February 26, 2024 10:01
Include from your theme file. Use [footnote]This is the content of my footnote.[/footnote] to add a footnote.
<?php
/**
* Footnotes
*/
function footnote($atts, $content = '') {
global $footnote_number, $footnote_contents;
$footnote_number ??= 0;
$footnote_contents ??= [];
$footnote_number++;
@Dan-Q
Dan-Q / download-geocache-logs.user.js
Created August 23, 2023 14:59
Userscript to download all of the logs on a Geocaching.com cache page as JSON
// ==UserScript==
// @name Download JSON cachelogs
// @namespace dllogs.geocaching.danq.me
// @match https://www.geocaching.com/geocache/*
// @grant GM_registerMenuCommand
// @version 1.0
// @author Dan Q
// @description Download all logs against a particular Geocaching.com geocache as a JSON file
// ==/UserScript==
@Dan-Q
Dan-Q / _no_code_page_.php
Last active December 28, 2023 18:01
Hacky PHP to produce a "blank" web page which somehow has content when viewed in Firefox. Sample page at https://danq.me/wp-content/no-code-webpage/, explanation at https://danq.me/nocode
<?php
// half-hearted CSS minification
$css = preg_replace(
array('/\s*(\w)\s*{\s*/','/\s*(\S*:)(\s*)([^;]*)(\s|\n)*;(\n|\s)*/','/\n/','/\s*}\s*/'),
array('$1{ ','$1$3;',"",'} '),
file_get_contents('linked.css')
);
// embed as a data: uri
$base64css = rtrim(strtr(base64_encode($css), '+/', '-_'), '=');
@Dan-Q
Dan-Q / setup-foundry.sh
Last active September 29, 2023 13:28
Configuration script for a basic setup of FoundryVTT on Debian 12. See https://danq.me/easy-foundryvtt for a full explanation.
# Foundry + Nginx install script for Debian 12
# --------------------------------------------
# Perequisites:
# - unzip - used to decompress Foundry once downloaded
# - nodejs - required to run Foundry
# - nvm - used to install pm2
# - ufw - firewall: used to ensure that connections can only be made to Foundry via Nginx, among other benefits
# - nginx - provides HTTPS frontend to Foundry
# - certbot - gets free SSL certificate, used by Nginx
@Dan-Q
Dan-Q / referer-faker.php
Last active September 26, 2023 01:38
This PHP script can be used to "proxy" content from third-party sites that block or modify their responses based on the Referer: header.
<?php
define('SECRET_PASSWORD', 'YOUR-SECRET-PASSWORD-GOES-HERE');
if($_GET['pw'] != SECRET_PASSWORD) http_response_code(403) && die();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, $_GET['referer']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);