Skip to content

Instantly share code, notes, and snippets.

View Dan-Q's full-sized avatar
🦆

Dan Q Dan-Q

🦆
View GitHub Profile
#!/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 / WEREWOLV.BAS
Created July 17, 2023 14:43
Source code for the 1985 Amstrad CPC version of Tim Hartnell's Werewolves and Wanderer, as adapted for publication in The Amazing Amstrad Omnibus by Martin Fairbanks.
10 REM WEREWOLVES AND WANDERER
20 GOSUB 2600:REM INTIALISE
30 GOSUB 160
40 IF RO<>11 THEN 30
50 PEN 1:SOUND 5,100:PRINT:PRINT "YOU'VE DONE IT!!!":GOSUB 3520:SOUND 5,80:PRINT "THAT WAS THE EXIT FROM THE CASTLE!":SOUND 5,200
60 GOSUB 3520
70 PRINT:PRINT "YOU HAVE SUCCEEDED, ";N$;"!":SOUND 5,100
80 PRINT:PRINT "YOU MANAGED TO GET OUT OF THE CASTLE"
90 GOSUB 3520
100 PRINT:PRINT "WELL DONE!"
@Dan-Q
Dan-Q / ev-ssl-ca-experiment.sh
Created September 4, 2018 21:39
Experiment to use OpenSSL to establish an EV-capable CA and issue illigitimate certificates which will be accepted and displayed as full valid EV certificates by Microsoft Internet Explorer and Edge on appropriately-configured Windows computers.
#!/bin/bash
# The following steps, which were tested on Ubuntu 18.04 LTS and on the Ubuntu-powered Linux for Windows Subsystem on Windows,
# will:
#
# * Compile a recent version of OpenSSL (you can skip this step and use your package maintainer's version if you prefer, but you
# might have to tweak a few bits)
# * Create a separate set of configuration files suitable for configuring a basic CA capable of signing EV certificates
# * Create such a CA (hackerca.local / HackerCA EV Root CA)
# * Create a certificate request for a site, hackersite.local, belonging to company "Barclays PLC [GB]"
@Dan-Q
Dan-Q / radio.garden-region-bypass.user.js
Last active March 15, 2023 11:57
Userscript to facilitate bypassing the (UK) region lock on radio.garden
// ==UserScript==
// @name radio.garden: bypass region restrictions (e.g. UK)
// @namespace dqne.me.radio.garden
// @match http://radio.garden/*
// @grant none
// @version 1.0
// @author Dan Q <https://danq.me/>
// @description Adds a secondary player interface to radio.garden which still works even on region-blocked radio stations. Allows listening to non-UK stations from the UK.
// @run-at document-idle
// ==/UserScript==
@Dan-Q
Dan-Q / strikecalendar-to-ical.rb
Last active February 23, 2023 15:38
Tool to extract strike action calendar from www.strikecalendar.co.uk and convert to .ics format
#!/bin/env ruby
# Run with e.g.:
# ruby strikecalendar-to-ical.rb > output.ics
# PLEASE READ AND UNDERSTAND SOURCE CODE FIRST: THERE'S A MAJOR SECURITY RISK ON LINE 25
# Dependencies
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
@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');
#!/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')
@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);