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 / 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)
string.chars.map{|c|"#{CHARS[c[0]/16]}#{CHARS[c[0]%16]}"}.join
end
program = <<-EOF
@Dan-Q
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 https://protonsforbreakfast.wordpress.com/2013/01/08/amazing-dice-rediscovering-surprise/
# Discussed on http://www.reddit.com/r/tabletopgamedesign/comments/1aibz9/grime_dice_might_make_a_good_basis_for/
# More info: http://grime.s3-website-eu-west-1.amazonaws.com/
class DiceSet < Array
# Returns an array of all of the possible outcome totals of throwing this DiceSet
def outcomes
@Dan-Q
Dan-Q / c301.rb
Created April 5, 2013 10:19
Cookieless tracking using HTTP 301s
#!/usr/bin/ruby
#
# Author: Dan Q (dan@scatmania.org)
# More information: http://www.scatmania.org/?p=4600
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
@Dan-Q
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 http://datagenetics.com/blog/april12012/index.html
# 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
Dan-Q / index.php
Created January 4, 2014 12:33
Improved version of getButterly's teleprompter script, originally found at http://getbutterfly.com/jquery-tv-teleprompter-script/. This version does not require MySQL and needs no set-up before it works. It's still vulnerable to unescaped inputs damaging the settings.
<?php
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
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 https://github.com/textcreationpartnership,
# 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 https://danq.me/2015/04/22/eebo-tcp-hackathon, this
@Dan-Q
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.
#!/bin/bash
# Concrete5 Console<?php /*
cd `dirname $0`
php -dauto_prepend_file=`basename "$0"` -a
cd -
exit
*/
define('DIR_BASE','.');
define('C5_ENVIRONMENT_ONLY',true);
include('index.php');
@Dan-Q
Dan-Q / target-blank-vulnerability.html
Created August 26, 2016 08:59
Demonstration of the target="_blank" vulnerability in many websites.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>target="_blank" vulnerability demo</title>
<style>
body {
margin: 0;
overflow: hidden;
}
@Dan-Q
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
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>
<html>
<head>
<meta charset="utf-8" />
<title>YouTube Video Wall</title>
<style type="text/css">
body {
margin: 0;
background: black;
color: white;