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 / extract-features.rb
Created April 22, 2015 09:17
A tool written during the EEBO-TCP Hackathon at the Weston Library, University of Oxford, in March 2015. Extracts markup features from XML documents and produces HTML tables showing their frequency across a corpus.
#!/usr/bin/env ruby
# Run in a directory containing any number of XML files from the EEBO-TCP project,
# which can be acquired via Github at,
# among other ways. It uses the Nokogiri XML parser to perform frequency counts of
# each of the selected features (specified in CSS3 syntax) and outputs the result
# to a HTML table (by default, called "output.html").
# Thrown together quickly for the EEBO-TCP Hackathon at the Weston Library in Oxford
# in March 2015, as described at, this
Dan-Q / grimesweeper.rb
Created March 18, 2013 15:51
Calculates the probabilities of victory using unusual combinations of non-transitive dice. Does not make any optimisations (e.g. ruling out always-lose/always-win combinations on a DiceSet) at all, so it quickly slows down if, for example, two players each throw six dice.
#!/usr/bin/env ruby
# Grimesweeper
# Calculates the victory chances if different combinations of Grime Dice (non-transitive dice) against one another
# Inspired by
# Discussed on
# More info:
class DiceSet < Array
# Returns an array of all of the possible outcome totals of throwing this DiceSet
def outcomes
Dan-Q / zen-hangman.rb
Created December 11, 2013 13:21
What's the hardest-to-guess word in Hangman, for any given number of letters? Give this program a wordlist.txt and a number of letters, and it'll tell you, by repeatedly playing an optimised game against itself and then sorting the results.
#!/usr/bin/env ruby
# -*- coding: iso-8859-1 -*-
# Inspired by
# Comes up with the "hardest words" to guess, in hangman, assuming the player is playing optimally
# (choosing the letter most-likely to appear, given a dictionary of all candidate words and the
# letters guessed so far [because hangman guesses are not independent; they affect the gamestate
# either by saying "this letter DOES NOT feature" or by saying "this letter features in THESE
# positions"])
# Result: a "hardest hangman words" dictionary?
Dan-Q / index.php
Created January 4, 2014 12:33
Improved version of getButterly's teleprompter script, originally found at This version does not require MySQL and needs no set-up before it works. It's still vulnerable to unescaped inputs damaging the settings.
if(isset($_POST['submit'])) {
$save_result = file_put_contents('settings.ini',
array("[prompter]", "\n",
"text_size=", $_POST['text_size'], "\n",
"text_colour=", $_POST['text_colour'], "\n",
"text_speed=", $_POST['text_speed'], "\n",
"container_height=", $_POST['container_height']));
if($save_result === false) die('Failed to save settings: check write permission on settings.ini.');
Dan-Q / c5console
Created August 19, 2016 10:41
Concrete5 Console. Bash script (with embedded/self-referencing PHP script) to provide an interactive PHP console onto your Concrete5 installation. Place in Concrete5 directory, mark executable, and run.
# Concrete5 Console<?php /*
cd `dirname $0`
php -dauto_prepend_file=`basename "$0"` -a
cd -
Dan-Q / target-blank-vulnerability.html
Created August 26, 2016 08:59
Demonstration of the target="_blank" vulnerability in many websites.
<!DOCTYPE html>
<meta charset="utf-8" />
<title>target="_blank" vulnerability demo</title>
body {
margin: 0;
overflow: hidden;
Dan-Q / split-message.rb
Created November 2, 2016 21:28
Ugly Ruby code to split a message into two messages with alternate words escaped.
msg = "Your message goes here."
[true, false].each{|x|puts msg.split(' ').map{|w|(x = !x) ? w : ('_'*w.length)}.join(' ')}
# Result:
# ____ message ____ here.
# Your _______ goes _____
Dan-Q / YouTube-Video-Wall.html
Created November 4, 2016 12:24
Simple one-file tool for the Bodleian Libraries' Heritage Window (5x3 HD video wall). Shows thumbnails for a YouTube playlist, then picks one video and plays it, then repeats.
<!DOCTYPE html>
<meta charset="utf-8" />
<title>YouTube Video Wall</title>
<style type="text/css">
body {
margin: 0;
background: black;
color: white;

Keybase proof

I hereby claim:

  • I am Dan-Q on github.
  • I am dq ( on keybase.
  • I have a public key whose fingerprint is B00A 55DA C3F5 9B51 7CA3 F64F 6342 1D24 3218 A6AC

To claim this, I am signing this object:

Dan-Q / whitespace-a-like.rb
Created November 26, 2012 23:06
Encode a Ruby program into a version composed almost entirely of unicode whitespace characters. Decodes itself on the fly.
#!/usr/bin/env ruby
# encoding: utf-8
CHARS = %w{                       ​ ‌ ‍    }
def encode(string){|c|"#{CHARS[c[0]/16]}#{CHARS[c[0]%16]}"}.join
program = <<-EOF