Skip to content

Instantly share code, notes, and snippets.

View DominikPeters's full-sized avatar

Dominik Peters DominikPeters

View GitHub Profile
@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}
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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