Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Dan Q Dan-Q

🚀
View GitHub Profile
@Dan-Q
Dan-Q / jigidi-helper.js
Last active January 22, 2023 14:12
Experimental under-development code to streamline Jigidi solving.
View jigidi-helper.js
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 / _no_code_page_.php
Last active January 28, 2023 13:43
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
View _no_code_page_.php
<?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 / wp-mastodon-sync.rb
Created November 30, 2022 11:28
Script to push DanQ.me posts to @blog@danq.me via the Mastodon API and get back replies (mentions), favourites (likes), and reblogs (reposts)
View wp-mastodon-sync.rb
#!/usr/bin/php
<?php
define('Q23_WP_DIR', '/www/danq.me/www');
define('Q23_MASTODON_SERVER', 'm.danq.me');
define('Q23_MASTODON_META_KEY', 'q23_mastodon_sync');
define('Q23_MASTODON_META_SYNDICATION_LINKS', 'mf2_syndication');
define('Q23_MASTODON_SYNC_POSTS_LIMIT', 30);
define('Q23_MASTODON_SYNC_REPLIES_LIMIT', 30);
define('Q23_MASTODON_COMMENT_USER_AGENT', 'Q23 DanQ.me Mastodon Comment Backfeeder');
@Dan-Q
Dan-Q / referer-faker.php
Last active January 16, 2023 20:08
This PHP script can be used to "proxy" content from third-party sites that block or modify their responses based on the Referer: header.
View referer-faker.php
<?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);
View finger-to-wordpress.rb
#!/usr/bin/env ruby
# This program gets executed (by /etc/efingerd/luser) when somebody runs finger something@danq.me
# The output is returned directly to them
# For more information, see https://danq.me/wp-finger
require 'mysql2'
require 'word_wrap'
require 'word_wrap/core_ext'
db = Mysql2::Client.new(username: 'WORDPRESS_DB_USERNAME', password: 'WORDPRESS_DB_PASSWORD', database: 'WORDPRESS_DB_NAME')
View browser-basic-auth-test.rb
#!/usr/bin/env ruby
require 'bundler'
Bundler.require
require 'sinatra'
set :bind, '0.0.0.0'
set :port, 80
def show_credentials(request)
<<-EOF
@Dan-Q
Dan-Q / get-twitter-avatar.js
Created June 2, 2021 08:33
Uses Puppeteer to get the current URL of any user's Twitter avatar by screen-scraping, for times when you're just too lazy to get some OAuth tokens and implement the Twitter API v2. Pass twitter usernames as command-line arguments.
View get-twitter-avatar.js
/* Copyright (c) 2021 Dan Q; released under the MIT License. */
const Puppeteer = require('puppeteer');
getAvatar = async (twitterUsername) => {
const browser = await Puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
const page = await browser.newPage();
await page.goto(`https://twitter.com/${twitterUsername}`);
await page.waitForSelector('a[href$="/photo"] img[src]');
const url = await page.evaluate(()=>document.querySelector('a[href$="/photo"] img').src);
@Dan-Q
Dan-Q / clicker.rbw
Created August 25, 2020 12:46
Runs in the background, makes an (inaudible?) sound every so often to keep your soundbar awake.
View clicker.rbw
# Dependencies
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'win32-sound', require: 'win32/sound'
end
include Win32
FREQUENCY = 37 # Hz; 37-32767 - what pitch sound?
DURATION = 1 # Ms - how long to play for?
@Dan-Q
Dan-Q / loader-modern-browsers.js
Last active August 9, 2020 17:50
Lazy-loading CSS without introducing a mandatory JS dependency; see https://danq.me/lazy-css-without-js/ for more or https://danq.me/2020/08/09/lazy-css/ for discussion
View loader-modern-browsers.js
// This version works with modern browsers
function lazyLoadCSS(){
[...document.querySelectorAll('noscript[lazyload]')].forEach(ns=>ns.outerHTML=ns.innerHTML);
}
(document.readyState != 'loading') ? lazyLoadCSS() : document.addEventListener('DOMContentLoaded', lazyLoadCSS);
@Dan-Q
Dan-Q / wp-post-kinds-prefix-kind-in-rss.php
Last active March 1, 2020 11:23
Add Post Kinds for Wordpress kinds as a prefix to titles in RSS. https://danq.me/2020/03/01/post-kinds-rss/
View wp-post-kinds-prefix-kind-in-rss.php
<?php
// Make titles in RSS feed be prefixed by the Kind of the post.
function add_kind_to_rss_post_title(){
$kinds = wp_get_post_terms( get_the_ID(), 'kind' );
if( ! isset( $kinds ) || empty( $kinds ) ) return get_the_title(); // sanity-check.
$kind = $kinds[0]->name;
$title = get_the_title();
return trim( "[{$kind}] {$title}" );
}