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 / _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 / 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)
#!/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 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);
#!/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')
#!/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.
/* 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.
# 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
// 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/
<?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}" );
}
@Dan-Q
Dan-Q / countdown.html
Last active September 3, 2019 14:32
Workday countdown timer
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Countdown</title>
<style type="text/css">
body {
margin: 0;
font-family: sans-serif;
font-size: 8vh;