Skip to content

Instantly share code, notes, and snippets.

View DominikPeters's full-sized avatar

Dominik Peters DominikPeters

View GitHub Profile
@DominikPeters
DominikPeters / input-search-dark-mode.css
Created December 20, 2021 21:54
Styling the ⤫ cancel button of input[type=search] for dark mode in Chrome and Safari
/* Makes the clear/cancel/delete button bright instead of dark when in dark mode */
@media (prefers-color-scheme: dark) {
input[type="search"]::-webkit-search-cancel-button {
filter: invert(1);
}
}
@DominikPeters
DominikPeters / paris-annual-passes.md
Last active January 18, 2022 15:40
List of touristic annual pass offers in Paris / Ile-de-France

This is a list of annual memberships / annual passes that allow unlimited access to tourist attractions in Paris and Ile-de-France. Prices as of early 2022.

@DominikPeters
DominikPeters / latexbuild.yml
Created January 24, 2022 17:44
Github Action for compiling a LaTeX document and FTP uploading it to your webserver
# to use, customize values in [[BRACKETS]] and add the password as a secret in the repo settings
name: Build LaTeX document
on: [push]
jobs:
build_latex:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
- name: Compile LaTeX document
@DominikPeters
DominikPeters / microtype-texpad.md
Last active January 27, 2022 19:55
Make Texpad and TexpadTex ignore microtype

I often use Texpad on documents that use the microtype package which makes texpad fall back to PDFLaTeX. Instead I want Texpad to ignore the included package. Here is a way to do this, by adding a fake empty local microtype package.

Make a folder with a fake microtype package:

mkdir .fakemicrotype
echo "\ProvidesPackage{microtype}" > .fakemicrotype/microtype.sty

Add the new folder to the TexpadTex search path: (Command+Shift+. to show hidden files in the folder picker)

@DominikPeters
DominikPeters / remove-jstor-watermark.py
Created February 24, 2022 23:45
Remove JSTOR watermark from PDF
# first install pdftk. For recent MacOS version, get it here: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
import os
os.system(f"pdftk input.pdf output uncompressed.pdf uncompress")
with open("fixed.pdf", "wb") as outfile:
for line in open("uncompressed.pdf", "rb"):
patterns = [
b"This content downloaded from",
@DominikPeters
DominikPeters / nash-dynamic.py
Last active April 26, 2022 12:37
Compute Nash via Dynamic
def nash(N, A, u, rounds=500):
"N is set of voters, A is set of alternatives, u is a utility dictionary"
"where u[i,x] >= 0 is the utility of i for x, usually either 0 or 1"
p = {x : 1/len(A) for x in A}
for _ in range(rounds):
q = {x : 0 for x in A}
for i in N:
util = sum(u[i,x] * p[x] for x in A)
for x in A:
q[x] += (1/len(N)) * (u[i,x] * p[x]) / util
@DominikPeters
DominikPeters / mallows.py
Last active May 4, 2022 13:04
Sample from a Mallows distribution
# Adapted from https://github.com/martinlackner/abcvoting/blob/6aacadb0e3e70e4f83a82225b05730f72a6230d4/abcvoting/generate.py#L166
def mallows(reference_ranking, dispersion):
distributions = []
for i in range(len(reference_ranking)):
distributions.append([dispersion ** (i - j) for j in range(i + 1)])
while True:
vote = []
for i in range(len(reference_ranking)):
pos = random.choices(range(i + 1), weights=distributions[i], k=1)[0]
@DominikPeters
DominikPeters / latex-snippets.md
Last active May 7, 2024 09:54
LaTeX snippets that I often use in papers

For arXiv, run

latexpand --empty-comments --keep-includes --expand-bbl document.bbl document.tex > document-arxiv-v1.tex

Website version style

\documentclass[11pt]{scrartcl}
\usepackage[a4paper, total={16cm, 24cm}]{geometry}
\usepackage{authblk}
@DominikPeters
DominikPeters / mes.js
Created August 10, 2023 10:41
JS implementation of the Method of Equal Shares with cost utilities and Add1U completion, including a pabulib file parser
// usage: node mes.js <path-to-pb-file>
const fs = require('fs');
const readline = require('readline');
function parsePBFile(filePath) {
return new Promise((resolve, reject) => {
const meta = {};
const projects = {};
const votes = {};
@DominikPeters
DominikPeters / prop-fairness.py
Created August 19, 2023 12:55
Optimization code to find distribution with optimum distortion with respect to proportional fairness (Paper "Optimized Distortion and Proportional Fairness in Voting" by Soroush Ebadian, Anson Kahng, Dominik Peters, and Nisarg Shah)
import cvxpy as cp
import math
def compute_hi(rankings):
"""Compute h_i(a) for all voters and alternatives."""
hi = []
for ranking in rankings:
h = {}
for a in ranking:
h[a] = set(ranking[:ranking.index(a)+1])