Skip to content

Instantly share code, notes, and snippets.

View DominikPeters's full-sized avatar

Dominik Peters DominikPeters

View GitHub Profile
@DominikPeters
DominikPeters / probabilistic_serial.py
Created April 29, 2020 01:08
Simple implementation of the Probabilistic Serial fair division mechanism
from fractions import Fraction
def probabilistic_serial(profile):
"input is a list of preference lists"
N = range(len(profile)) # agents
O = range(len(profile[0])) # items
supply = {o : Fraction(1,1) for o in O}
allocation = {(i,o) : Fraction(0,1) for i in N for o in O}
while any(supply.values()):
# in each iteration, at least one remaining item is fully depleted
@DominikPeters
DominikPeters / cayley_distance.py
Created April 29, 2020 01:19
Compute Cayley distance between two rankings
# for two permutations of [0,1,...,n], compute how many swaps (not necessarily adjacent)
# are needed to transform one into the other
# code uses: distance of a permutation from the identity permutation
# equals n - #cycles in the cycle notation of the permutation
def cayley_distance(x,y):
A = range(len(x))
inv_y = tuple(y.index(a) for a in A)
comp = tuple(x[inv_y[a]] for a in A)
cycles = 0
@DominikPeters
DominikPeters / nash_indivisible.py
Created April 29, 2020 04:01
Maximize Nash welfare for allocating indivisible goods
# Indivisible private goods, maximum Nash welfare
# Using Gurobi, this implements the ILP formulation from
# Caragiannis, Ioannis, et al.
# "The unreasonable fairness of maximum Nash welfare."
# ACM Transactions on Economics and Computation (TEAC) 7.3 (2019): 1-32.
from gurobipy import *
import math
import random
@DominikPeters
DominikPeters / __counterexamples_fair_division.txt
Last active March 8, 2024 07:02
Counterexamples in fair division
A collection of some counterexamples I've found for
fair allocation of indivisible goods, mostly via random sampling.
@DominikPeters
DominikPeters / merge_insertion.py
Created August 27, 2020 12:52
Python implementation of the merge insertion sort algorithm
# Implementation of the Merge Insertion sort algorithm
# -- a sort algorithm that is efficient w.r.t. number of pairwise comparisons
# based on the description in
# https://en.wikipedia.org/w/index.php?title=Merge-insertion_sort&oldid=959884881
# This is not intended to be time- or space-efficient.
# "less" is a function such that less(x,y) is true iff x should go to the left of y
# Dominik Peters, August 2020
# imports only needed for test at the bottom
from __future__ import print_function
@DominikPeters
DominikPeters / kemeny.py
Created August 29, 2020 23:23
Calculate Kemeny's rule using gurobipy
from gurobipy import *
import itertools
def better(vote, a, b):
return vote.index(a) < vote.index(b)
def kemeny(profile):
# a profile is a list of rankings, e.g. [(0,1,2),(1,2,0),(1,2,0)]
C = profile[0]
w = {}
@DominikPeters
DominikPeters / cmt-block-filters.txt
Last active October 26, 2022 09:18
Adblocker filters to hide clutter in reviews, CMT for AAAI 2023
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div>div>strong
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(4)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(5)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(6)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(7)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(8)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(9)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(10)
cmt3.research.microsoft.com##div[data-bind="foreach: questions"]>div.row:nth-of-type(15)
cmt3.research.microsoft.com##div[data-bind="foreach:reviews"] > h2
@DominikPeters
DominikPeters / yt-dl.applescript
Created December 2, 2021 04:28
AppleScript to call youtube-dl on the URL currently displayed by Google Chrome
# I use this together with BetterTouchTool
tell application "Google Chrome"
set theURL to URL of active tab of first window as string
end tell
tell application "Terminal"
do script "cd ~/Downloads && youtube-dl '" & theURL & "'"
end tell
@DominikPeters
DominikPeters / close-chrome-incognito.applescript
Created December 4, 2021 15:13
AppleScript for closing all incognito windows of Google Chrome
tell application "Google Chrome"
set allWindows to get every window
repeat with i in allWindows
set windowProperties to properties of i
set windowMode to mode of windowProperties
if windowMode is "incognito" then
close i
end if
end repeat
end tell
@DominikPeters
DominikPeters / lwarp-tips.md
Last active February 16, 2022 14:58
Some tips for using lwarp for Latex to HTML conversion

Replace natbib by biblatex to get citation links

\usepackage[backend=bibtex, style=authoryear-comp, natbib=true, sortcites=false]{biblatex}
\addbibresource{main.bib}

% optional if you want (Smith 1776) instead of (Smith, 1776)
\renewcommand*{\nameyeardelim}{\addspace}

\begin{document}