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
<?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), '+/', '-_'), '='); |
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
#!/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'); |
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
<?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); |
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
#!/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') |
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
#!/usr/bin/env ruby | |
require 'bundler' | |
Bundler.require | |
require 'sinatra' | |
set :bind, '0.0.0.0' | |
set :port, 80 | |
def show_credentials(request) | |
<<-EOF |
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
/* 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); |
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
# 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? |
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
// 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); |
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
<?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}" ); | |
} |
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
<!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; |