Skip to content

Instantly share code, notes, and snippets.

@betaveros
betaveros / aoc-2022-13.py
Created December 13, 2022 18:07
Solving https://adventofcode.com/2022/day/13 without a custom comparator or cmp_to_key
import json
# Determine the maximum number of layers of nesting an integer or list has.
# That is, the maximum number of lists any particular integer is directly or
# indirectly inside. 1 is depth 0, [1] is depth 1, [[1]] is depth 2, etc.
def compute_depth(x):
if isinstance(x, int): return 0
assert isinstance(x, list)
if not x: return 1
return 1 + max(map(compute_depth, x))
@betaveros
betaveros / cvxx.cls
Created October 6, 2021 00:49
✨ my cool résumé ✨
\ProvidesClass{cvxx}[2021/10/05 betaveros's CV class]
\NeedsTeXFormat{LaTeX2e}
% Distantly based on https://www.latextemplates.com/template/friggeri-resume-cv (?)
% Requires the FontAwesome font and LaTeX package (among others)
\DeclareOption{print}{\def\@cv@print{}}
\DeclareOption{public}{\def\@cv@public{}}
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{article}%
}
@betaveros
betaveros / pancakescon.user.js
Created March 20, 2021 02:09
pancakescon timezone converter
// ==UserScript==
// @name pancakescon timezone converter
// @version 1
// @namespace https://beta.vero.site/
// @include https://pancakescon.com/attend/
// @grant none
// @description poorly translate the times to your local time zone on pancakescon.com
// ==/UserScript==
function signed(n) {
@betaveros
betaveros / lektor_extensionless.py
Created September 3, 2020 06:56
Lektor plugin to work with extensionless URLs. Very hacky! Use at own risk.
# -*- coding: utf-8 -*-
import jinja2
from lektor.pluginsystem import Plugin
from lektor.admin.webui import LektorInfo
from lektor.context import url_to
class ExtensionlessPlugin(Plugin):
name = 'extensionless'
description = u'Monkey patch the Jinja environment to strip .html from URLs and the server to add .html to extensionless URLs'
@betaveros
betaveros / models.py
Created July 30, 2020 02:30
crude generic puzzlehunt models
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models import OuterRef, Exists, Sum, Q
from django.core.validators import MinValueValidator
import django.urls as urls
@betaveros
betaveros / 1374-ac.cpp
Created July 15, 2020 13:44
UVA 1374: Power Calculus
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define fori(i,s,e) for(int i = s; i < ((int)e); i++)
#define allof(s) (s).begin(), (s).end()
const int MAX = 3000;
@betaveros
betaveros / 1374.cpp
Created July 8, 2020 05:33
UVA 1374: Power Calculus (TLE version. how to improve?)
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define fori(i,s,e) for(int i = s; i < ((int)e); i++)
#define allof(s) (s).begin(), (s).end()
@betaveros
betaveros / 12558.cpp
Created July 8, 2020 05:32
UVA 12558: Egyptian Fractions
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
#define fori(i,s,e) for(int i = s; i < ((int)e); i++)
long long gcd(long long x, long long y) {
return y == 0 ? x : gcd(y, x % y);
}
@betaveros
betaveros / gist:9663e49011a722e82e835b8d86234ee4
Created February 10, 2020 03:28
C chords. thanks, music21
In [73]: for i in range(70):
...: print('C{} ='.format(i), end=" ")
...: try:
...: print(' '.join(pitch.nameWithOctave for pitch in ChordSymbol('C{}'.format(i)).pitches))
...: except Exception as e:
...: print(e)
...:
C0 = C3
C1 = C3 C3
C2 = C3 D3
major 40173
dominant 19633
minor 11501
minor-seventh 7156
major-seventh 2828
maj 1516
major-sixth 1442
dominant-ninth 1210
[] 1180
minor-sixth 692