View edit_distance.py
def distance(s, t, cache=None):
"""Return minimum edit distance between s and t, where an edit
is a character substitution, deletion, or addition.
"""
if not s:
return len(t)
if not t:
return len(s)
if cache is None:
View connect4.go
// A little "Connect Four" game
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strconv"
View server.go
// Simple HTTP server with regex-based router
package main
import (
"fmt"
"net/http"
"regexp"
)
View tiny-vdom-speed.html
<html>
<head><title>More speed tests</title></head>
<body>
<h1>More speed tests</h1>
<div id="main"></div>
<script>
/*
<ul>
{% for item in items %}
<li>item: {{ item }}</li>
View test_dom.html
<html>
<head>
<title>Test speed of various methods of building DOM</title>
</head>
<body>
Test speed of various methods of building DOM
</body>
<script>
View is_none_bytecode.diff
b66bbc41ce52efe667af0ba47a6098216b758236
diff --git a/Include/opcode.h b/Include/opcode.h
index 99c3b0ef81..dceedc662a 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -12,6 +12,8 @@ extern "C" {
#define ROT_THREE 3
#define DUP_TOP 4
#define DUP_TOP_TWO 5
+#define COMPARE_IS_NONE 6
View sliding_window_sort.py
"""Efficient sliding-window sorting of time-series data in CSV file.
Demo for http://stackoverflow.com/a/42398981/68707
Tested on Python 3.5.
"""
import collections
import csv
import datetime
View thread_test.py
"""Test how many threads we can run at once."""
import itertools
import threading
import time
import sys
import requests
View snakes_and_ladders.py
"""Calculate the average number of moves in a snakes and ladders game.
Because as a parent one gets roped into these board (boring?) games
every so often, and I wanted to calculate the average duration of a
snakes and ladders game. Turns out it's about 36 moves (though
admittedly that's for a single-player game). :-)
> python snakes_and_ladders.py
Played 10000 rounds, averaged 36.0559 moves, max 324 moves, took 0.508s
"""
View birthday_probability.py
"""Calculate the probability of generating a duplicate random number after
generating "n" random numbers in the range "d".
Usage: python birthday_probability.py n [d=365]
Each value can either be an integer directly, or in the format "2**x", where
x is the number of bits in the value.
For example, to calculate the probability that two people will have the same
birthday in a room with 23 people: