Skip to content

Instantly share code, notes, and snippets.

@kgaughan
kgaughan / gist:a6a31918ccf1baaa6d3f14abdf803bef
Last active December 15, 2016 18:50
Search algorithm outline

I've an idea for a merge sort variant that's been rattling around my head for a while.

The idea is that sorting is broken up into two phase: run identification and merging. This has some similarities to Timsort, but it's not quite the same thing.

In the run identification phase, runs are identified and recorded. There is some deperturbation to try an identify the longest runs possible near the potential end of runs where if the next element, x[i], is less than x[i-1] and x[i-2], it is swapped with x[i-1].

If no run longer than N can be identified since the last identified run by M elements, those M elements are sorted using insertion sort to create a run.

When we have a list of runs, we start merging adjacent pairs of runs, starting with the smallest adjacent pairs.

@kgaughan
kgaughan / rihannsu.c
Created December 12, 2016 15:56
Rihannsu word generator (with minor patching for modern C compilers)
/* Romulan word generator. */
/* Created by Diane Duane, */
/* ported to C by Curt Snyder */
/****************************************/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/* initialize 'r' values */
char r[10][3] = {"H'","Ae","D'","W","U","N'","R'","O","V","Ll"};
@kgaughan
kgaughan / sshd_config
Last active November 17, 2016 16:48
Modern crypto directives (2016)
KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256
certbot tlsa (--pkix-ta|--dane-ta|--pkix-ee|--dane-ee)+ # Usage field
(--cert|--spki) # Selector field
(--full|--sha256|--sha512) # Matching-Type
--port NUM
--transport (tcp|udp|sctp)
domain.name
Example:
$ certbot tlsa --dane-ee --spki --sha256 --port 587 --transport tcp mail.talideon.com
@kgaughan
kgaughan / mux.xml
Created June 10, 2016 17:21
EPP mux envelope
<?xml version="1.0"?>
<mux xmlns="foo">
(<src>...</src>|<dest>...</dest>)
<p>
<epp xmlns="...">
...
</epp>
</p>
</mux>
@kgaughan
kgaughan / gen_tlsa_hash.sh
Created February 26, 2016 19:48
Generate SHA256 hash for a given cert chain for use in a TLSA (DANE) record
#!/bin/sh
extract() {
openssl x509 -in $1 -noout -pubkey | openssl rsa -pubin -outform DER
}
digest() {
openssl dgst -sha256 -hex
}
/usr/ports/lang/gcc6-aux/work/gcc-6-20160214/gcc/ada/adaint.c: In function 'void __gnat_set_file_time_name(char*, time_t)':
/usr/ports/lang/gcc6-aux/work/gcc-6-20160214/gcc/ada/adaint.c:1487:13: error: invalid conversion from 'time_t {aka int}' to 'time_t* {aka int*}' [-fpermissive]
t = time ((time_t) 0);
^~~~~~~~~~
In file included from /usr/include/sys/time.h:471:0,
from /usr/ports/lang/gcc6-aux/work/gcc-6-20160214/gcc/system.h:324,
from /usr/ports/lang/gcc6-aux/work/gcc-6-20160214/gcc/ada/adaint.c:107:
/usr/include/time.h:154:8: note: initializing argument 1 of 'time_t time(time_t*)'
time_t time(time_t *);
@kgaughan
kgaughan / setup.py
Created February 17, 2016 12:16
Markdown to ReST on sdist in setup.py (untested, but the basic gist is correct)
import sys
# ...
if len(sys.argv) > 1 and sys.argv[1] == 'sdist':
import pypandoc
with open('README', 'w') as fh:
fh.write(pypandoc.convert('README.md', 'rst'))
setup(
@kgaughan
kgaughan / lib.php
Created January 12, 2016 16:09
AFK event example
<?php
function format($text) {
return str_replace(
array('<pre><code>', '<hr />', '<br />'),
array('<pre class="prettyprint"><code>', '<div class="hr"><hr></div>', '<br>'),
SmartyPants(Markdown(render_tags($text))));
}
function render_tags($text) {
return preg_replace_callback(
@kgaughan
kgaughan / gist:95bea100f9c451a90e47
Last active January 11, 2016 13:51
Single sign-on - this is only a thought experiment, and it likely full of holes.
Nomenclature:
The REQUESTING SYSTEM is the system requesting that some entity be
authenticated.
The AUTHENTICATING SYSTEM is the system the performs the authentication of an
entity for the requesting system.
The IDENTITY TOKEN is a token used by both systems to identify a user. An email
address would be the best candidate. The requesting system should tie this