Skip to content

Instantly share code, notes, and snippets.

Kieren Davies kierendavies

Block or report user

Report or block kierendavies

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:1447301
sudo tar jxvf wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2 -C /opt
sudo rm /usr/bin/wkhtmltopdf
sudo ln -s /opt/wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
rm wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2
kierendavies / herp
Created Jan 10, 2012
View herp
#! /usr/bin/python
from sys import argv
argv[0] = argv[0].split("/")[-1]
print " ".join(argv[::-1])
kierendavies /
Created Feb 19, 2012
Embedly Challenge code
# my first solution (lost) in the interactive interpreter used DP, but this
# is fast enough
fac = lambda x: reduce(lambda a, b: a * b, range(1, x + 1))
R = lambda x: sum(int(c) for c in str(fac(x)))
x = 1
while R(x) != 8001:
x += 1
kierendavies /
Created Oct 1, 2012
obfuscated hello world
# does not work with python 2.x
print("".join(map(lambda x: chr((lambda p, x: int(sum(map(lambda i: p[i]*x**(11-i), range(12))) + 0.001))([__import__("struct").unpack('>d', bytes([int(s[8*i:8*i+8], 2) for i in range(8)]))[0] for s in ["1011111101010000111010100110011000001101001100000110010001011111", "0011111110110000000101110100001011100000001010111100100101110011", "1011111111111010101001111000010001111000000111111001101001000100", "0100000000111001001101110000110101000110000001010100001100011000", "1100000001101110000010000010100110101001111010000000111011101101", "0100000010010111011001010111000101110010000010000101010111011100", "1100000010110111111110111100001101011100011011101001111111101100", "0100000011001111101011010010010111011011001011001000001110000011", "1100000011011001100001011001001010011100110001010011010100111001", "0100000011010110010101010110010000110001111011111110011001000111", "1100000010111111100000011000011000100110010110100001000110110110", "0100000001010001111
kierendavies /
Last active Dec 12, 2015
finds words which are mirror-image palindromes in elian script
# find words which are mirror-image palindromes in elian script
with open("/usr/share/dict/words", encoding="utf-8", errors="ignore") as fin:
words = [word.strip().lower() for word in fin.readlines()]
sub = {'i': 'c', 'h': 'b', 'k': 'q', 'j': 'p', 'm': 'm', 'l': 'r', 'o': 'o', 'n': 'n', 'a': 'g', 'c': 'i', 'b': 'h', 'e': 'e', 'd': 'd', 'g': 'a', 'f': 'f', 'y': 's', 'x': 'x', 'z': 't', 'q': 'k', 'p': 'j', 's': 'y', 'r': 'l', 't': 'z', 'w': 'w', 'v': 'v'}
for word in words:
kierendavies /
Created Apr 15, 2013
Google Code Jam 2013 Qualification Round Problem B
from itertools import product
T = int(input())
for t in range(T):
N, M = list(map(int, input().split()))
grid = [list(map(int, input().split())) for n in range(N)]
rowmax = list(map(max, grid))
kierendavies /
Created May 21, 2013
A dragon curve in pretty colours, produced by a floor turtle.
import turtle as t
from math import sin, pi, log
f = 1
l, r = True, False
t.bgcolor(0, 0, 0)
View bwt.clj
; Burrows-Wheeler Transform (and inverse)
(def string-start \u0098)
(defn bwt [s]
(map last
(sort-by vec
(take (inc (count s))
(iterate #(concat (rest %)
kierendavies / cube-puzzle-solver.rb
Last active Aug 29, 2015
Solver for the coloured-cubes puzzle that Caleb brought
View cube-puzzle-solver.rb
# This program solves a puzzle I encountered recently.
# The puzzle consists of four cubes, each face of which has one of four colours.
# The objective is to arrange them in a column so that, looking down each side
# of the column, the four visible colours are all different.
require 'pp'
require 'set'
# A cube with colours attributed to its faces.
class Cube
kierendavies /
Created Apr 23, 2015
An implementation of a minheap
import java.util.ArrayList;
import java.util.Random;
public class MinHeap<T extends Comparable<T>> {
private ArrayList<T> values;
public MinHeap() {
values = new ArrayList<T>();
You can’t perform that action at this time.