Skip to content

Instantly share code, notes, and snippets.

Ben Hoyt benhoyt

Block or report user

Report or block benhoyt

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
@benhoyt
benhoyt / join.awk
Created Nov 20, 2018
AWK program to compare time complexity of joining strings
View join.awk
# AWK program to compare time complexity of joining strings using a
# simple O(N^2) algorithm and a slightly more complex O(N log N) one.
# Join array elements, separated by sep: O(N^2) version
function join1(a, sep, i, s) {
for (i = 1; i+1 in a; i++) {
s = s a[i] sep
}
if (i in a) {
s = s a[i]
@benhoyt
benhoyt / mandelbrot.go
Created Sep 21, 2018
Go program to print the Mandelbrot set on stdout
View mandelbrot.go
// Print the Mandelbrot set on stdout
package main
import (
"fmt"
"math/cmplx"
)
const (
@benhoyt
benhoyt / edit_distance.py
Created May 8, 2018
Calculate edit distance with simple (memoized) recursive algorithm
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:
@benhoyt
benhoyt / connect4.go
Last active Jan 25, 2018
Connect 4 solver
View connect4.go
// A little "Connect Four" game
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strconv"
@benhoyt
benhoyt / server.go
Last active Nov 29, 2017
Simple HTTP server with regex-based router in Go
View server.go
// Simple HTTP server with regex-based router
package main
import (
"fmt"
"net/http"
"regexp"
)
@benhoyt
benhoyt / tiny-vdom-speed.html
Created Oct 28, 2017
Speed test of tiny virtual dom and merge algorithm
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>
@benhoyt
benhoyt / test_dom.html
Created Oct 25, 2017
Test speed of various methods of building DOM
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>
@benhoyt
benhoyt / is_none_bytecode.diff
Created Jun 27, 2017
Add COMPARE_IS_NONE opcode to CPython for performance
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
@benhoyt
benhoyt / sliding_window_sort.py
Created Feb 22, 2017
Efficient sliding-window sorting of time-series data in CSV file (in Python)
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
@benhoyt
benhoyt / thread_test.py
Created Nov 3, 2016
Test how many threads we can run at once
View thread_test.py
"""Test how many threads we can run at once."""
import itertools
import threading
import time
import sys
import requests
You can’t perform that action at this time.