Skip to content

Instantly share code, notes, and snippets.

@tomviner
tomviner / maze.py
Last active December 17, 2015 02:38 — forked from teh/maze.py
import sys
import random
import turtle
W = H = 10
def outer_walls(w, h):
# Add some walls to confine the maze
# And yield them in order of a perimeter walk
@tomviner
tomviner / gist:5396962
Last active December 16, 2015 07:09
Birthday decoding
import re
secret = """0b10010000b11000010b11100000b11100000b11110010b1000000b10000100b11010010b11100100b11101000b11010000b11001000b11000010b11110010b1000000b10101100b11010010b11011100b11001010b11100100b100001"""
binaries = re.findall(r'0b[01]+(?=0b|$)', secret)
ords = map(eval, binaries)
letters = map(chr, ords)
print ''.join(letters)
# Happy Birthday Viner!
@tomviner
tomviner / README.md
Last active December 15, 2015 19:19
Offline package installation, and download script to pre-run. Include package_sources in your repo!

Offline installs

This started with Jonathan Hartley's input to the "pypi's going slowly twiscusion" he suggested:

To download sdists into dirname "pip install -d dirname -r reqs.txt"

Then to install "pip install -r reqs.txt --no-index --find-links=file://dirname". This bit works even w/ no network...

So I've downloaded the packages with --download and made this install script:

@tomviner
tomviner / binarySplitCountChange.dot
Last active December 15, 2015 18:30
Scala Q3 countChange generated dot notation of call graph
graph binarySplitCountChange {
"1:ch(3,List(1, 2, 3))" -- "2:ch(2,List(1, 2, 3))";
"1:ch(3,List(1, 2, 3))" -- "2:ch(3,List(2, 3))";
"2:ch(2,List(1, 2, 3))" -- "3:ch(1,List(1, 2, 3))";
"2:ch(2,List(1, 2, 3))" -- "3:ch(2,List(2, 3))";
"3:ch(1,List(1, 2, 3))" -- "4:ch(0,List(1, 2, 3))";
"3:ch(1,List(1, 2, 3))" -- "4:ch(1,List(2, 3))";
"4:ch(1,List(2, 3))" -- "5:ch(-1,List(2, 3))";
"4:ch(1,List(2, 3))" -- "5:ch(1,List(3))";
"5:ch(1,List(3))" -- "6:ch(-2,List(3))";
@tomviner
tomviner / page.html
Created March 21, 2013 15:26
DDoS protection by CloudFlare
$ GET http://xyz.com/14015/forxxx
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Just a moment...</title>
<link rel="stylesheet" media="screen" href="/cdn-cgi/styles/js-challenge/error.css" type="text/css">
</head>
<body>
@tomviner
tomviner / bash_colours.sh
Created March 13, 2013 17:24
Bash prompt colours, including coping with venvs
# colours are from http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
# in $WORKON_HOME/postactivate
PS1="(`basename $VIRTUAL_ENV`)$BASE_PS1"
# in $WORKON_HOME/postdeactivate
PS1=$BASE_PS1
# in startup eg ~/.bashrc
@tomviner
tomviner / admin.py
Last active December 14, 2015 21:49
from django.contrib import admin
from django.db.models.loading import get_models
# BaseAdmin does things like default list_display to all fields
from core.admin import BaseAdmin
import models as legacy_models
for mod in get_models(legacy_models):
if mod not in admin.site._registry:
if(typeof jQuery !== 'undefined'){
jQuery(function($) {
var dateUpdated = "";
var reDate = /(\d+)\/(\d+)\/(\d+)/;
var reIssues = /issues\/\d+/;
var titleDate = $('p.author a').last().attr('title');
var style= 'position: fixed;bottom: 0px;margin-bottom: 0px;width: 100%;padding: 12px 0px 13px 30px;background-position-y: 12px;';
var warning = '<div class="flash warning" style="'+style+'">This issue has been updated since you last saw it. <a href="javascript:location.reload(true);">Refresh now</a></div>';
@tomviner
tomviner / reldate.js
Created February 27, 2013 10:22
The next Redmine update: keep relative times up-to-date
// locate and parse all relative time links on the page
var reDate = /(\d+)\/(\d+)\/(\d+)/;
jQuery('a[title]').map(function(){
var a = jQuery(this);
if ((a.text() && a.text().length===0) || !a.attr('title').match(reDate) ){return 0}
var d = new Date(a.attr('title').replace(reDate, "$3/$2/$1"));
return 'make_relative('+d+')';
})
@tomviner
tomviner / updated?
Last active December 13, 2015 21:38 — forked from seb-thomas/updated?
with console.logs
var YOUR_API_KEY = ''
var dateUpdated = "";
function changeTitle() {
var favi = jQuery('[rel="shortcut icon"]');
var titleDate = jQuery('p.author a').last().attr('title');
var reDate = /(\d+)\/(\d+)\/(\d+)/;
//Swap year and day, convert to Date obj
titleDate = (titleDate).replace(reDate, "$3/$2/$1");