Skip to content

Instantly share code, notes, and snippets.

I 4281
IV 3311
V 2250
i 1289
bVII 1207
vi 944
bVI 587
ii 521
bIII 343
iv 211
@betaveros
betaveros / advent-2019-4.py
Created December 4, 2019 16:17
Advent of Code 2019 Day 4, DP solution
"""
For part 1 for counting solutions ≤ x, our DP state can be dp[n][f][d][le] = the count of digit-strings with
- n digits
- where the first digit is f
- and a double digit has appeared iff d = 1
- that are less than equal to the last n digits of x iff le = 1.
"""
def part1_dp(x): # x should be list of digits
@betaveros
betaveros / mums-leaderboard.js
Last active August 10, 2019 14:05
Add comparable solve times to the MUMS Puzzlehunt leaderboard
(() => {window.setInterval(() => {
document.querySelectorAll('.betaveros').forEach((node) => {
node.parentNode.removeChild(node);
});
const makeNode = (t) => {
const span = document.createElement('span');
span.className = 'betaveros';
span.textContent = t;
return span;
};
@betaveros
betaveros / makefuzz.py
Created April 16, 2019 23:41
some really sketchy makefile patching to get openssl fuzzing to work
import sys, os, subprocess
def check(msg):
if not input(msg + ' (y/n): ').lower().startswith('y'):
print('Aborting')
sys.exit()
subprocess.run('./config enable-fuzz-libfuzzer -DPEDANTIC enable-asan enable-ubsan no-shared -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=fuzzer-no-link enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment enable-tls1_3 enable-weak-ssl-ciphers enable-rc5 enable-md2 enable-ssl3 enable-ssl3-method enable-nextprotoneg --debug'.split(), env={'CC': 'clang'})
check('Does config look ok?')
with open('Makefile') as infile:
@betaveros
betaveros / fp-optimized.asm
Created May 22, 2018 20:45
function pointers
0000000100000f40 <__Z1av>:
100000f40: 55 push rbp
100000f41: 48 89 e5 mov rbp,rsp
100000f44: b8 03 00 00 00 mov eax,0x3
100000f49: 5d pop rbp
100000f4a: c3 ret
100000f4b: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0]
0000000100000f50 <_main>:
100000f50: 55 push rbp
@betaveros
betaveros / c.hs
Created November 27, 2017 19:04
Enumerative Combinatorics with Haskell, Splash 2017
import Control.Monad
import Data.List
-- Haskell comments look like this, lines that start with two hyphens.
{- You can also write range comments like this. -}
-- We did not write the type annotations (lines with ::) during class, and in
-- fact if you delete them Haskell will supply (more general) type signatures.
-- You can see what type Haskell thinks the things we've defined are by running
b8 01 00 00 00 mov eax,0x1
b8 37 13 00 00 mov eax,0x1337
b9 01 00 00 00 mov ecx,0x1
b9 37 13 00 00 mov ecx,0x1337
48 c7 c0 01 00 00 00 mov rax,0x1
48 c7 c0 37 13 00 00 mov rax,0x1337
48 c7 c1 01 00 00 00 mov rcx,0x1
48 c7 c1 37 13 00 00 mov rcx,0x1337
49 c7 c0 01 00 00 00 mov r8,0x1
49 c7 c0 37 13 00 00 mov r8,0x1337
@betaveros
betaveros / fn_minus.xml
Created January 9, 2017 15:45
Karabiner XML for mapping fn+- (fn-hyphen) to a legitimate minus sign, cobbled together from sone online sources I forget
<?xml version="1.0"?>
<root>
<item>
<name>Change fn+- to (minus sign)</name>
<appendix>You need to enable Unicode Hex Input and U.S. input sources.</appendix>
<identifier>private.fn_minus</identifier>
<autogen>__KeyToKey__
KeyCode::MINUS, ModifierFlag::FN,
<!-- change input source to Unicode -->
from __future__ import division, print_function
def partial_differences(xs):
return [x2 - x1 for (x1, x2) in zip(xs, xs[1:])]
def index_of_max(xs):
return max(enumerate(xs), key=lambda pair: pair[1])[0]
# given a list of floats, compute a tempo and a timestamp
def tempo(xs, max_beats):
@betaveros
betaveros / c.hs
Last active November 25, 2016 03:19
combinatorics!
import Control.Monad
import Data.List
-- Haskell comments look like this, lines that start with two hyphens.
{- You can also write range comments like this. -}
-- We did not write the type annotations (lines with ::) during class, and in
-- fact if you delete them Haskell will supply (more general) type signatures.
-- You can see what type Haskell thinks the things we've defined are by running