Skip to content

Instantly share code, notes, and snippets.


Dan Q Dan-Q

View GitHub Profile
View browser-basic-auth-test.rb
#!/usr/bin/env ruby
require 'bundler'
require 'sinatra'
set :bind, ''
set :port, 80
def show_credentials(request)
Dan-Q / get-twitter-avatar.js
Created Jun 2, 2021
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(`${twitterUsername}`);
await page.waitForSelector('a[href$="/photo"] img[src]');
const url = await page.evaluate(()=>document.querySelector('a[href$="/photo"] img').src);
Dan-Q / clicker.rbw
Created Aug 25, 2020
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 ''
gem 'win32-sound', require: 'win32/sound'
include Win32
FREQUENCY = 37 # Hz; 37-32767 - what pitch sound?
DURATION = 1 # Ms - how long to play for?
Dan-Q / loader-modern-browsers.js
Last active Aug 9, 2020
Lazy-loading CSS without introducing a mandatory JS dependency; see for more or for discussion
View loader-modern-browsers.js
// This version works with modern browsers
function lazyLoadCSS(){
(document.readyState != 'loading') ? lazyLoadCSS() : document.addEventListener('DOMContentLoaded', lazyLoadCSS);
Dan-Q / wp-post-kinds-prefix-kind-in-rss.php
Last active Mar 1, 2020
Add Post Kinds for Wordpress kinds as a prefix to titles in RSS.
View wp-post-kinds-prefix-kind-in-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 / countdown.html
Last active Sep 3, 2019
Workday countdown timer
View countdown.html
<!DOCTYPE html>
<meta charset="utf-8" />
<style type="text/css">
body {
margin: 0;
font-family: sans-serif;
font-size: 8vh;
Dan-Q / bbc-news-rss-filter-sport-out.rb
Last active May 13, 2019
Filter the Sport section out of the BBC News RSS feed and put the result into a Backblaze B2 bucket
View bbc-news-rss-filter-sport-out.rb
#!/usr/bin/env ruby
# # Sample crontab:
# # At 41 minutes past each hour, run the script and log the results
# 41 * * * * ~/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
# * b2 - command line tools, described below
Dan-Q / consolepic.rb
Created Dec 12, 2018
Convert a (small!) PNG image into JS/CSS that 'draws' the image in a Firefox/Chrome debug console.
View consolepic.rb
#!/usr/bin/env ruby
# Bundler/Gemfile (inline mode)
require 'bundler/inline'
gemfile do
source ''
gem 'chunky_png'
# Check for PNG file passed at command line or error out
Dan-Q / google-authenticator.rb
Last active Mar 8, 2019
Command-line Google Authenticator (TOTP)
View google-authenticator.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
# encoding: utf-8
require 'bundler/inline'
gemfile do
source ''
gem 'rotp'
gem 'thor'
View Basic Reddit Content Exporter.js
// Basic Reddit Content Exporter
// Author: Dan Q <>
// License: The Unlicense <> / Public Domain
// 1. Go to and log in (logging in means that we don't have to worry about a modhash)
// 2. Edit this script to include YOUR username and the content you want to download
// 3. Paste this script into your browser console
const username = 'avapoet'; // <-- your username goes here (be sure to be logged in as it, too!)
const content = 'submitted'; // <-- valid options: overview (everything), submitted (posts), comments,